log4j

Spring Boot(十)Logback和Log4j2集成与日志发展史

ぐ巨炮叔叔 提交于 2019-12-23 21:14:14
一、简介 Java知名的日志有很多,比如:JUL、Log4j、JCL、SLF4J、Logback、Log4j2,那么这些日志框架之间有着怎样的关系?诞生的原因又是解决什么问题?下面一起来看。 1.1 JUL Java有自己的日志框架JUL(Java Util Logging)在java.util.logging下,因为对开发者不友好,使用成本太高和日志级别分类不清晰的问题,所有很少有开发者用。 1.2 Log4j 因为JUL的缺陷问题,这就给了Log4j机会,所有Log4j一经推出就迅速风靡全球。 1.3 JCL JCL是Jakarta Commons-Logging的缩写,Jakarta在这里指的是一个组织,而不是印度的首都雅加达,Jakarta,一个早期的Apache开源项目,用于管理各个Java子项目,诸如Tomcat, Ant, Maven, Struts, JMeter, Velocity, JMeter, Commons等。2011年12月,在所有子项目都被迁移为独立项目后,Jakarta名称就不再使用了。 JCL诞生的初衷是因为Java自身的一些包用了JUL,而Log4j用户使用的有很多,那么JCL就是提供一套API来实现不同Logger之间的切换。 1.4 SLF4J SLF4J(Simple Logging Facade For Java)简单日志门面

日志框架--logback

笑着哭i 提交于 2019-12-23 21:13:36
logback背景介绍: SLF4J(Simple Logging Facade for Java)是一个日志API接口,SLF4J提供 TRACE, DEBUG, INFO, WARN, ERROR五种级别,而log4j和logback就是对SLF4J的具体实现。logback的性能优于log4j。 logback-core:其它两个模块的基础模块 logback-classic:它是log4j的一个改良版本,同时它完整实现了slf4j API使你可以很方便地更换成其它日志系统如log4j或JDK14 Logging logback-access:访问模块与Servlet容器集成提供通过Http来访问日志的功能 Maven坐标:logback-classic包含了logback-core,不需要再单独引用了。 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.21</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.7</version> <

Difference between Log4jConfigListener and Log4jServletContextListener while configuring log4j

别说谁变了你拦得住时间么 提交于 2019-12-23 18:51:41
问题 I am trying to deploy a spring web app in tomcat with log4j logging. From what I see from reading up on log4j configuration you can do it as follows - <context-param> <param-name>log4jConfiguration</param-name> <param-value>/WEB-INF/webdynamo-log4j.xml</param-value> </context-param> <context-param> <param-name>log4j.refresh.interval</param-name> <param-value>120</param-value> </context-param> And you also need a listener for this to work - Couple of places I have seen - <listener> <listener

Failure to add a custom converter to log4j

家住魔仙堡 提交于 2019-12-23 16:34:38
问题 Following here, I'd like to extend log4j by a custom convertor, to add the shiro user name to the log. Here's my code: @Plugin(name = "shiro", type = "Converter") @ConverterKeys({"susr", "shiro"}) public class ShiroUserConverter extends LogEventPatternConverter { private static final ShiroUserConverter INSTANCE = new ShiroUserConverter(); private ShiroUserConverter() { this("shiro", "shiro"); // not sure why! } protected ShiroUserConverter(String name, String style) { super(name, style); }

Java - Rich logging in web services

喜欢而已 提交于 2019-12-23 16:25:12
问题 I have a simple web service like this: @WebService public class MyWebService { @WebMethod public String ProcessQuery(@WebParam(name="query") String q) { // Logging here: User IP, etc. } public static void main(String[] args) throws Exception { String address = "http://127.0.0.1:8023/_WebServiceDemo"; Endpoint.publish(address, new MyWebService()); new DocumentServer(); System.out.println("Listening: " + address); } } I want to add a logging method for my service to extract information. I've

can not get grizzly logging to work, nothing written to my log4j log file

随声附和 提交于 2019-12-23 15:29:44
问题 I have a simple Java/Spring program using a standard log4j.properties file to control logging, which is working fine. When we added Grizzly via: GrizzlyHttpServerFactory.createHttpServer(uri, resourceConfig) things work (i.e. the server in fact serves...but I get no log output. I have an explicit entry in log4j.properties for "org.glassfish.grizzly". I've gone so far as to debug into Grizzly's ExtendedLogger class and can see that its getting close to logging but then doesn't. 回答1: Turns out

java: log4j: problem with jar executable

南楼画角 提交于 2019-12-23 12:17:04
问题 My log4j is working fine when I run "java pakcage.Main" from command line, but when I run the same program using executable jar like "java -jar myjar.jar" I'm getting the following err: log4j:WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system properly log4j.jar and log4j.properties are threre in my manifest's Class-Path . I'm sure it worked properly once, but after rebuild it is not working. 回答1: You can only list jar files or directories as part of a

How to escape only message instead of all row in log4j?

流过昼夜 提交于 2019-12-23 11:55:21
问题 I have the following PatternLayout: public class EscapedEnhancedPatternLayout extends EnhancedPatternLayout { @Override public String format(LoggingEvent event) { return StringEscapeUtils.escapeJava(super.format(event)); } } but this escapes full logging row. I want to have something like this but only for message. but LoggingEvent class has not setMessage and setRenderedMessage methods. And I don't see copy constructor at LoggingEvent . If LoggingEvent had copy constructor I can inherited

log4J: Failure in post-close rollover action using TimeBasedRollingPolicy

若如初见. 提交于 2019-12-23 11:45:08
问题 I have setup TimeBasedRollingPolicy to rollout the file every minute (for test purpose) and the problem I am facing is a warning and no zip or gz file is being created. Warning is: log4j:WARN Failure in post-close rollover action I attached the source to figure-out the problem but have no success yet. Am I missing any configuration in my log4j.xml? <appender name="errorAppender" class="org.apache.log4j.rolling.RollingFileAppender"> <param name="File" value="C:/error.log"/> <param name="Append

Include microsecond timestamps in log4j logging?

寵の児 提交于 2019-12-23 11:44:53
问题 Is it possible to have microsecond level timestamps in log4j logging? This is on linux running Java 1.6. We have a couple servers right next to each other (synced via LAN to the same NTP server), and I'd like to have microseconds in the log lines. If log4j doesn't offer this, does logback? 回答1: Log4j does not include microsecond precision timestamps. Logback does not currently include microsecond precision timestamps but future versions of logback probably will. 来源: https://stackoverflow.com