如果您对如何从Storm禁用/关闭日志记录功能和storm日志感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解如何从Storm禁用/关闭日志记录功能的各种细节,并对storm日志进行深入的分析,
如果您对如何从Storm禁用/关闭日志记录功能和storm 日志感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解如何从Storm禁用/关闭日志记录功能的各种细节,并对storm 日志进行深入的分析,此外还有关于Aop实现请求日志记录功能、Apache Airflow:控制日志记录[禁用/调整日志记录级别]、ASP.NET Core使用Log4net实现日志记录功能、blazeds 自带的日志记录功能的实用技巧。
本文目录一览:- 如何从Storm禁用/关闭日志记录功能(storm 日志)
- Aop实现请求日志记录功能
- Apache Airflow:控制日志记录[禁用/调整日志记录级别]
- ASP.NET Core使用Log4net实现日志记录功能
- blazeds 自带的日志记录功能
如何从Storm禁用/关闭日志记录功能(storm 日志)
当我们从本地群集运行时,我想关闭默认提供的日志记录功能。当前,它在控制台上记录了很多信息。
以下是日志示例:
261 [main] INFO backtype.storm.daemon.task - Shut down task Getting-Started-Toplogie-1-1376388324:22261 [main] INFO backtype.storm.daemon.task - Shutting down task Getting-Started-Toplogie-1-1376388324:12262 [Thread-24] INFO backtype.storm.util - Async loop interrupted!2276 [main] INFO backtype.storm.daemon.task - Shut down task Getting-Started-Toplogie-1-1376388324:12278 [main] INFO backtype.storm.daemon.worker - Terminating zmq context2279 [main] INFO backtype.storm.daemon.worker - Disconnecting from storm cluster state context2279 [main] INFO backtype.storm.daemon.worker - Waiting for heartbeat thread to die2279 [Thread-27] INFO backtype.storm.util - Async loop interrupted!2308 [main] INFO backtype.storm.testing - Shutting down in process zookeeper2309 [main] INFO backtype.storm.testing - Done shutting down in process zookeeper2309 [main] INFO backtype.storm.testing - Deleting temporary path /tmp/255fe7c8-1407-4f43-8771-2217905232ab
在阅读了许多文档之后,我得到了以下代码,我可以从类中关闭日志记录。
static Logger logger = Logger.getLogger(TopologyMain.class);public static void main(String[] args) throws InterruptedException, AlreadyAliveException, InvalidTopologyException { logger.setLevel((Level) Level.FATAL); logger.debug("Here is some DEBUG"); logger.info("Here is some INFO"); logger.warn("Here is some WARN"); logger.error("Here is some ERROR"); logger.fatal("Here is some FATAL"); }}
输出(正确): 0 [main] FATAL TopologyMain - Here is some FATAL
但是我需要更改Storm / zookeper等的日志记录配置。
有人可以帮忙吗?
更新 :以下是我尝试过的代码,但是它不起作用。我尝试使用0.7.1、0.8.2和0.9.0-wip *版本
//Configuration Config conf = new Config(); conf.put(Config.TOPOLOGY_DEBUG, false); //Tried this alone conf.setDebug(false); //Tried this alone & tried both together as well.. No change :-(
答案1
小编典典Storm确实很健谈,可以提供很多信息,但是如果您想使其静音,可以将Config.TOPOLOGY_DEBUG设置为false。
当您将Config.TOPOLOGY_DEBUG设置为true时,您在告诉Storm每次从任何喷嘴或螺栓发射出元组时都记录一条消息。
Aop实现请求日志记录功能
环境 SpringBoot2.0
maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
自定义一个注解MyLog
package com.zns.annotation;
import java.lang.annotation.*;
@Target({ ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MyLog
{
/** 描述 */
String desc() default "";
}
增加一个切面MyLogAspect
package com.zns.aspect;
import com.google.gson.Gson;
import com.zns.annotation.MyLog;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.stream.Collectors;
@Aspect
@Component
@EnableAsync
public class MyLogAspect {
private static final Logger logger = LoggerFactory.getLogger(MyLogAspect.class);
@Autowired
private Gson gson;
/**
* 用包名的方式定义切入点
*/
/*@Pointcut("execution(* com.zns.controller.*.*(..))")
public void pointCut() {
}*/
/**
* 用注解的方式定义切入点
*/
@Pointcut("@annotation(com.zns.annotation.MyLog)")
public void pointCut() {
}
/**
* 前置通知
*
* @param joinPoint
*/
@Before("pointCut()")
public void doBeforeAdvice(JoinPoint joinPoint) {
//System.out.println("进入方法前执行.....");
}
/**
* 后置异常通知
*/
@AfterThrowing("pointCut()")
public void throwss(JoinPoint jp) {
//System.out.println("方法异常时执行.....");
}
/**
* 后置最终通知,final增强,不管是抛出异常或者正常退出都会执行
*/
@After("pointCut()")
public void after(JoinPoint jp) {
//System.out.println("方法最后执行.....");
}
/**
* 处理完请求,返回内容
*
* @param ret
*/
@AfterReturning(returning = "ret", pointcut = "pointCut()")
public void doAfterReturning(Object ret) {
//System.out.println("方法的返回值 : " + ret);
}
/**
* 环绕通知,相当于MethodInterceptor
*/
@Around("pointCut()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
//请求返回信息
Object res = null;
//请求开始时间
long startTime = System.currentTimeMillis();
//请求结束时间
long endTime = 0L;
//请求时长(毫秒)
long duration = 0L;
try {
//执行方法
res = joinPoint.proceed();
endTime = System.currentTimeMillis();
duration = endTime - startTime;
return res;
} finally {
try {
//方法执行完成后增加日志
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//客户端操作系统
String osName = System.getProperty("os.name");
//客户端操作系统版本
String osVersion = System.getProperty("os.version");
//客户端浏览器的版本类型
String userAgent = request.getHeader("user-agent");
//请求ip
String requestIp = request.getRemoteAddr();
//请求url
String requestUrl = request.getRequestURL().toString();
//请求uri
String requestUri = request.getRequestURI();
//请求方式 get,post等
String requestType = request.getMethod();
//请求参数
String requestParam = getParams(joinPoint, request);
//请求执行的类路径
String classPath = signature.getDeclaringTypeName();
//请求执行的方法名
String methodName = signature.getName();
//获取注解的自定义属性
MyLog annotation = signature.getMethod().getAnnotation(MyLog.class);
String desc = "";
if (annotation != null) {
desc = annotation.desc();
}
//输出
System.out.println("客户端操作系统: " + osName);
System.out.println("客户端操作系统版本: " + osVersion);
System.out.println("客户端浏览器的版本类型: " + userAgent);
System.out.println("请求ip: " + requestIp);
System.out.println("请求url: " + requestUrl);
System.out.println("请求uri: " + requestUri);
System.out.println("请求方式: " + requestType);
System.out.println("请求参数: " + requestParam);
System.out.println("请求执行的类路径: " + classPath);
System.out.println("请求执行的方法名: " + methodName);
System.out.println("请求执行的方法描述: " + desc);
System.out.println("请求开始时间: " + startTime);
System.out.println("请求结束时间: " + endTime);
System.out.println("请求时长(毫秒): " + duration);
System.out.println("请求返回信息: " + gson.toJson(res));
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
/**
* 获取请求参数 支持get,post(含与不含@RequestBody接收都可以获取)
*
* @param joinPoint
* @param request
* @return
* @throws Exception
*/
public String getParams(JoinPoint joinPoint, HttpServletRequest request) throws Exception {
String method = request.getMethod();
String queryString = request.getQueryString();
String params = "";
Object[] args = joinPoint.getArgs();
if (args.length > 0) {
if ("POST".equals(method)) {
Object object = args[0];
//过滤掉 ServletRequest 和 ServletResponse 类型的参数
Object paramObject = Arrays.stream(args).filter(t -> !(t instanceof ServletRequest) && !(t instanceof ServletResponse)).collect(Collectors.toList());
params = gson.toJson(paramObject);
} else if ("GET".equals(method)) {
params = queryString;
}
params = URLDecoder.decode(params, "utf-8");
}
return params;
}
}
控制器调用测试
package com.zns.controller;
import com.zns.annotation.MyLog;
import com.zns.bean.Person;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@RestController
public class TestController {
@RequestMapping(path = "/hello")
@MyLog(desc = "这是一个hello")
public String testHello(HttpServletRequest request, HttpServletResponse response) throws Exception {
return "hello,world";
}
@RequestMapping(path = "/query")
@MyLog(desc = "这是一个查询")
public Person query(@RequestBody Person person,HttpServletRequest request, HttpServletResponse response) throws Exception {
return new Person(person.getId(), person.getName());
}
}
Apache Airflow:控制日志记录[禁用/调整日志记录级别]
我正在使用通过pip安装的Airflow 1.7.1.3
我想将调度程序正在执行的工作流的日志记录限制为错误级别。除了在settings.py文件中设置日志文件位置之外,找不到任何其他内容。
另外,在线资源也使我在这里参加了这个Google小组讨论,但在这里也没有太多信息
知道如何控制Airflow中的日志记录吗?
ASP.NET Core使用Log4net实现日志记录功能
一、安装Log4net
1、使用Nuget包进行安装
在依赖项上面右键,选择“管理NuGet程序包”,如下图所示:
在浏览界面输入log4net,然后点击安装,如下图所示:
2、使用程序包管理器控制台进行安装
使用Install-Package Log4net命令进行安装,如下图所示:
二、配置log4net使用的配置文件
配置文件如下:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <!-- This section contains the log4net configuration settings --> <log4net> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger - %message%newline" /> </appender> <appender name="FileAppender" type="log4net.Appender.FileAppender"> <file value="log-file.log" /> <appendToFile value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file value="D:\study\logfile/" /> //指定日志文件保存的目录 <appendToFile value="true" /> <rollingStyle value="Composite" /> <staticLogFileName value="false" /> <datePattern value="yyyyMMdd''.log''" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="1MB" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender> <!-- Setup the root category, add the appenders and set the default level --> <root> <level value="ALL" /> <appender-ref ref="ConsoleAppender" /> <appender-ref ref="FileAppender" /> <appender-ref ref="RollingLogFileAppender" /> </root> </log4net> </configuration>
三、在Startup.cs类里面配置使用log4net
public static ILoggerRepository repository { get; set; } public Startup(IConfiguration configuration) { Configuration = configuration; repository = LogManager.CreateRepository("NETCoreRepository"); // 指定配置文件 XmlConfigurator.Configure(repository, new FileInfo("log4net.config")); }
四、在控制器里面注入log4net
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using log4net; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using NetCoreLogDemo.Models; namespace NetCoreLogDemo.Controllers { public class HomeController : Controller { private ILog log; public HomeController(IHostingEnvironment hostingEnv) { this.log = LogManager.GetLogger(Startup.repository.Name, typeof(HomeController)); } public IActionResult Index() { log.Error("测试日志"); return View(); } public IActionResult About() { ViewData["Message"] = "Your application description page."; return View(); } public IActionResult Contact() { ViewData["Message"] = "Your contact page."; return View(); } public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } } }
测试结果:
到此这篇关于ASP.NET Core使用Log4net实现日志记录功能的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持。
- Asp.Net Core配置多环境log4net配置文件的全过程
- C#使用log4net打日志
- .net项目使用日志框架log4net
- .NET6在WebApi中使用日志组件log4net
- asp.net中使用log4net详解
- 在.NET 6中使用日志组件log4net的方法
- .NET Core下使用Log4Net记录日志的方法步骤
- ASP.NET MVC中使用log4net的实现示例
- ASP.NET MVC使用Log4Net记录异常日志并跳转到静态页
blazeds 自带的日志记录功能
在mxml添加<mx:TraceTarget level="1"/>,level代表日志等级,就是all,debug,info,error等。。。。
在配置文件中打开:
<logging>
<targetlevel="Debug">
<properties>
<prefix>[Flex] </prefix>
<includeDate>true</includeDate>
<includeTime>true</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>true</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
tomcat console:
[Flex] 02/09/2011 16:38:38.812 [WARN] [Configuration] HttpFlexSession has not been registered as a listener in web.xml for this application so no events will be dispatched to FlexSessionAttributeListeners or FlexSessionBindingListeners. To correct this,register flex.messaging.HttpFlexSession as a listener in web.xml. [Flex] 02/09/2011 16:38:38.890 [DEBUG] [Endpoint.FlexSession] FlexSession created with id '7FAD3A28CFC179E2783613C195B0B985' for an Http-based client connection. [Flex] 02/09/2011 16:38:38.906 [INFO] [Endpoint.General] Channel endpoint my-amf received request. [Flex] 02/09/2011 16:38:39.015 [DEBUG] [Endpoint.AMF] Deserializing AMF/HTTP request Version: 3 (Message #0 targetURI=null,responseURI=/1) (Array #0) [0] = (Typed Object #0 'flex.messaging.messages.CommandMessage') operation = 5 correlationId = "" messageId = "EB7AB2B6-EFA3-6054-8930-09927DCCFAB0" timestamp = 0 headers = (Object #1) DSId = "nil" DSMessagingVersion = 1 destination = "" body = (Object #2) clientId = null timetoLive = 0 [Flex] 02/09/2011 16:38:39.156 [DEBUG] [Endpoint.AMF] Serializing AMF/HTTP response Version: 3 (Message #0 targetURI=/1/onResult,responseURI=) (Externalizable Object #0 'DSK') (Object #1) DSMPIO = (Typed Object #2 'flex.messaging.messages.MessagePerformanceInfo') serverPreAdapterTime = 0.0 serverPreAdapterExternalTime = 0.0 infoType = null sendTime = 1.29724071914E12 recordMessageTimes = false serverPrePushTime = 0.0 pushedFlag = false serverPostAdapterExternalTime = 0.0 receiveTime = 0.0 messageSize = 0.0 overheadTime = 0.0 recordMessageSizes = false serverPostAdapterTime = 0.0 DSMessagingVersion = 1.0 DSId = "655EA75C-C708-C158-A04B-EEACB497D065" 1.297240719031E12 (Byte Array #3,Length 16) (Byte Array #4,Length 16) (Byte Array #5,Length 16) [Flex] 02/09/2011 16:38:39.203 [INFO] [Endpoint.General] Channel endpoint my-amf received request. [Flex] 02/09/2011 16:38:39.218 [DEBUG] [Endpoint.AMF] Deserializing AMF/HTTP request Version: 3 (Message #0 targetURI=null,responseURI=/2) (Array #0) [0] = (Typed Object #0 'flex.messaging.messages.RemotingMessage') source = null operation = "sayHello" messageId = "E2EC4EA3-01CB-F22C-0CCB-09927D7EA4CB" timestamp = 0 headers = (Object #1) DSId = "655EA75C-C708-C158-A04B-EEACB497D065" DSEndpoint = "my-amf" destination = "FirstJavaClassRemoteObject" body = (Array #2) [0] = "hi~你好" clientId = null timetoLive = 0 [Flex] 02/09/2011 16:38:39.218 [DEBUG] [Service.Remoting] Adapter 'java-object' called 'com.test.FirstJavaClass.sayHello(java.util.Arrays$ArrayList (Collection size:1) [0] = hi~你好 )' [Flex] 02/09/2011 16:38:39.218 [DEBUG] [Service.Remoting] Result: '你说的是:hi~你好' [Flex] 02/09/2011 16:38:39.218 [DEBUG] [Endpoint.AMF] Serializing AMF/HTTP response Version: 3 (Message #0 targetURI=/2/onResult,responseURI=) (Externalizable Object #0 'DSK') "你说的是:hi~你好" (Object #1) DSMPIO = (Typed Object #2 'flex.messaging.messages.MessagePerformanceInfo') serverPreAdapterTime = 0.0 serverPreAdapterExternalTime = 0.0 infoType = null sendTime = 1.297240719218E12 recordMessageTimes = false serverPrePushTime = 0.0 pushedFlag = false serverPostAdapterExternalTime = 0.0 receiveTime = 0.0 messageSize = 0.0 overheadTime = 0.0 recordMessageSizes = false serverPostAdapterTime = 0.0 1.297240719218E12 (Byte Array #3,Length 16)
flex console:
0AE5DD11-6F38-C4D2-9B38-09927560A495' producer set destination to 'FirstJavaClassRemoteObject'. '0AE5DD11-6F38-C4D2-9B38-09927560A495' producer sending message 'E2EC4EA3-01CB-F22C-0CCB-09927D7EA4CB' 'my-amf' channel endpoint set to http://localhost:8080/flex_blazeds3/messagebroker/amf 'my-amf' channel settings are: <channel id="my-amf" type="mx.messaging.channels.AMFChannel"> <endpoint uri="http://{server.name}:{server.port}/flex_blazeds3/messagebroker/amf"/> <properties/> </channel> 'my-amf' pinging endpoint. 'my-amf' channel is connected. 'my-amf' channel sending message: (mx.messaging.messages::RemotingMessage)#0 body = (Array)#1 [0] "hi~你好" clientId = (null) destination = "FirstJavaClassRemoteObject" headers = (Object)#2 messageId = "E2EC4EA3-01CB-F22C-0CCB-09927D7EA4CB" operation = "sayHello" source = (null) timestamp = 0 timetoLive = 0 '0AE5DD11-6F38-C4D2-9B38-09927560A495' producer connected. '0AE5DD11-6F38-C4D2-9B38-09927560A495' producer ackNowledge of 'E2EC4EA3-01CB-F22C-0CCB-09927D7EA4CB'.
我们今天的关于如何从Storm禁用/关闭日志记录功能和storm 日志的分享就到这里,谢谢您的阅读,如果想了解更多关于Aop实现请求日志记录功能、Apache Airflow:控制日志记录[禁用/调整日志记录级别]、ASP.NET Core使用Log4net实现日志记录功能、blazeds 自带的日志记录功能的相关信息,可以在本站进行搜索。
本文标签: