log4j

Number of loggers used

我怕爱的太早我们不能终老 提交于 2019-12-18 04:50:30
问题 I'm working on a very large java application with log4j, and I was wondering if there is a way to extract in runtime the number of active loggers? Or what are the existing loggers in the application? My end goal is to get a list of all loggers and change their level in runtime. Thank you. 回答1: You could try something like: Enumeration allLoggers = Logger.getRootLogger() .getLoggerRepository() .getCurrentLoggers(); Then iterate over allLoggers. 回答2: to get the loggers use one of these Logger

Rolling logs by both size and time

泄露秘密 提交于 2019-12-18 04:11:04
问题 I use RollingFileAppender of log4j 1.2.16 , which rolls log files, when they reach a certain size. Now I would like to roll log files daily and when they reach a certain size. Thus there will be one or more log files per day. For example, myapp.log myapp-17.12.2013.log myapp-16.12.2012.log myapp-16.12.2012.1.log myapp-16.12.2012.2.log Is there an off-the-shelf appender, which does it already? 回答1: There are indeed two options: use LogBack with its size and time triggering policy: http:/

Rolling logs by both size and time

元气小坏坏 提交于 2019-12-18 04:10:04
问题 I use RollingFileAppender of log4j 1.2.16 , which rolls log files, when they reach a certain size. Now I would like to roll log files daily and when they reach a certain size. Thus there will be one or more log files per day. For example, myapp.log myapp-17.12.2013.log myapp-16.12.2012.log myapp-16.12.2012.1.log myapp-16.12.2012.2.log Is there an off-the-shelf appender, which does it already? 回答1: There are indeed two options: use LogBack with its size and time triggering policy: http:/

how to create log in specific location when using log4j in java desktop application

与世无争的帅哥 提交于 2019-12-18 03:35:28
问题 I am using log4j in Eclipse for logging messages in a java desktop application. I want that the log should be created in a specific folder (Specifically, in the folder which contains source folder 'src' and classes folder 'bin'). Is it possible to set this in log4j.properties? How to ensure that log is created at this location only? 回答1: I would go with Saket's reply. But instead of hardcoding the location its always better to have a relative path. If you started your application from a main

Log4j Properties in a Custom Place

*爱你&永不变心* 提交于 2019-12-18 02:45:50
问题 I'm using Apache Commons Logging and SLF4J with log4j, but I also want to use the log4j.properties in a custom place like conf/log4.properties. Here is the problem: If i use PropertyConfigurator.configure("conf/log4j.properties"); then my app is tied to log4j and defeats the purpose of having ACL and SLF4J. What is the best way to configure it without the app ever knowing what the logging implementation is? 回答1: I think the easiest thing to do is specify the location of the file using the

SpringBoot整合日志管理

谁说胖子不能爱 提交于 2019-12-18 00:23:24
SpringBoot整合日志管理 使用Aop统一处理Web请求日志: 添加配置文件log4j.properties: #log4j.rootLogger=CONSOLE,info,error,DEBUG log4j.rootLogger=info,error,CONSOLE,DEBUG log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd-HH-mm} [%t] [%c] [%p] - %m%n log4j.logger.info=info log4j.appender.info=org.apache.log4j.DailyRollingFileAppender log4j.appender.info.layout=org.apache.log4j.PatternLayout log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd-HH-mm} [%t] [%c] [%p] - %m%n log4j.appender

Can we use all features of log4j2 if we use it along with slf4j api?

邮差的信 提交于 2019-12-17 23:36:48
问题 We have migrated all our code to use the slf4 API to use generic APIs, however now we are thinking of upgrading from log4j 1.x to log4j 2.x. Will we be able to use all the features of log4j2 if we use the slf4j API and log4j2 as the implementation? 回答1: The Log4j2 API is richer than the SLF4J API, and many Log4j2 API features are not accessible via SLF4J. See below for details. Features of the Log4j2 implementation, like Async Loggers, Lookups, Filters, Layouts and Appenders are controlled

External log4j.xml file

大憨熊 提交于 2019-12-17 22:07:12
问题 I am trying to run a jar with the log4j.xml file on the file system outside the jar like so: java -jar MyJarName.jar -cp=/opt/companyName/pathToJar/ log4j.configuration=log4j.xml argToJar1 argToJar2 I have also tried: java -jar MyJarName.jar -cp=/opt/companyName/pathToJar/ log4j.configuration=/opt/companyName/pathToJar/log4j.xml argToJar1 argToJar2 The log4j.xml is file is in the same directory as the jar (/opt/companyName/pathToJar/), yet I still get the standard warning message: log4j:WARN

Sample xml configuration for log4j, have a 'main' java application and want to write to file

旧街凉风 提交于 2019-12-17 19:57:32
问题 Are there any example log4j configuration files (XML). I have a java main application. I want log4j to output to console AND write to file. Any examples of this would be greatly appreciated. I'm using netbeans if that matters. 回答1: Just have more than one appender in your log4j.xml, like this: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'> <appender name=

What is the proper way to configure SMTPAppender in log4j?

て烟熏妆下的殇ゞ 提交于 2019-12-17 19:53:30
问题 I'm trying to configure log4j to use the SMTPAppender but I keep getting relay access denied errors. I get this error when executing my code on my laptop AND straight from my shared hosting environment. Here's the relevant config: #CONFIGURE SMTP log4j.appender.email=org.apache.log4j.net.SMTPAppender log4j.appender.email.SMTPHost=mydomain.com log4j.appender.email.SMTPUsername=myuser log4j.appender.email.SMTPPassword=mypw log4j.appender.email.From=myuser@mydomain.com log4j.appender.email