I am upgrading from log4j1.x to log4j-2.8.2
I am trying to convert my existing log4j.properties file to equivalent log4j2.xml.
My first question is can I write log4j2.proeprties file instead of log4j2.xml file?
I found some equivalent tags to log4j.proeprties file in log4j2.xml.
I did not find tags for the below lines. can anybody suggest on this?
# LoggerFactory for ESAPI to utilize Log4J
log4j.loggerFactory=org.owasp.esapi.reference.Log4JLoggerFactory
log4j.category.Default=ALL, CONSOLE, RollingFile2, edelivery
log4j.rootCategory=OFF
log4j.logger.org.apache=INFO
log4j.logger.IntrusionDetector=ERROR
log4j.logger.org.springframework=WARN
Thanks in advance.
What i am sure is:
See the last three lines:
log4j.logger.org.apache=INFO
log4j.logger.IntrusionDetector=ERROR
log4j.logger.org.springframework=WARN
I think in log4j.xml they should be instead of like these below:
<Logger name="org.apache" level="INFO"/>
<Logger name="IntrusionDetector" level="ERROR"/>
<Logger name="org.springframework" level="WARN"/>
And what I am not sure is:
these two lines:
log4j.category.Default=ALL, CONSOLE, RollingFile2, edelivery
log4j.rootCategory=OFF
I guess you have configured some appenders with the name in above line like:
<appender name="CONSOLE">
other proerties....
</appender>
so i think you could try to use these in your log4j.xml:
<root>
<appender-ref ref="ALL" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="RollingFile2" />
<appender-ref ref="edelivery" />
</root>
And What I really don't know is:
log4j.loggerFactory=org.owasp.esapi.reference.Log4JLoggerFactory
I Know nothing about esapi so i could not suggest how to deal with it, hope someone else to give more answer.
Related
I want to remove the unnecessary log's that are generated automatically by log4j when i run my suite, I only want the log's which i wrote in the code, please help.
As you can see my actual log's starts from Launched flipcart.com and end with Closed the current window
Also check the log4j2.xml file.
See second answer in How to exclude a single Class from a Log4j Logger / Appender?
Replace
<logger name="com.example.FifthClass">
<level value="FATAL"/>
</logger>
with e.g.
<logger name="io.netty">
<level value="FATAL"/>
</logger>
I'm looking at the source code of some application. It is using Spring framework, Apache Tiles, JSP, Log4j, java, javascript, jquery, jqplot, Jsch, and etc.
I know where the logs are created. (a/b/logs) However, when I look at source code, I don't know how logs are created under the folder name 'logs'. I looked at log4j.xml, web.xml , property files. I found the code for how the path 'a/b' is created, but not logs. Also that folder has 4 types of logs. And they are name in a pattern like access.20181227001 , errors.20182111. I want to know where I have to look to find how the logs are created in this manner.
Log4J.xml
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p [%c] %m%n" />
</layout>
</appender>
<appender name="console-infolog" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p %m%n" />
</layout>
</appender>
<!-- Application Loggers -->
<logger name="com.dsmentoring.chakan" additivity="false">
<level value="debug" />
<appender-ref ref="console"/>
</logger>
<!-- 3rdparty Loggers -->
<logger name="org.springframework.core">
<level value="error"/>
</logger>
<!-- Bean logger -->
<logger name="org.springframework.beans">
<level value="error"/>
</logger>
<!-- Context logger -->
<logger name="org.springframework.context">
<level value="error"/>
</logger>
<!-- Web logger -->
<logger name="org.springframework.web">
<level value="error"/>
</logger>
<logger name="org.springframework.ldap" additivity="true">
<level value="error"/>
</logger>
<!-- LDAP logger -->
<logger name="com.unboundid.ldap" additivity="true">
<level value="error"/>
</logger>
<!-- Root Logger -->
<root>
<priority value="off" />
<appender-ref ref="console" />
</root>
To sum up :
1) Is there a way to configure where logs are created and how they are created (4 types of logs) Other than log4j.xml, xml files and property files? I looked at all the java, jsp, js code but can't seem to find the configuration for logs. So I want to know if there are other ways to do that or where I should look for those configuration.
2) The 'logs' folder is possibly default for log4j?
ldap.properties
#LDAP Connection Info
ldap.host=192.168.0.17
ldap.port=22389
ldap.userName=cn=directory manager
ldap.password= 9074B18A0DE2D50C068D37B60BE5DFDE
ldap.baseDN=o=sso30root
ldap.defaultLoadSize=1000
ldap.start=start-ds
ldap.stop=stop-ds
ldap.workdir=/home/KB_openDJ // logs are created under this path
// /home/KB_openDJ/logs
In other java class, they use this.
#Value("${ldap.workdir}")
private String WORK_DIR;
// I ommited many lines in between
try{
diskUsage = sigar.getFileSystemUsage(WORK_DIR);
diskIOInfo.setDiskRead((int)(diskUsage.getDiskReadBytes()));
diskIOInfo.setDiskWrite((int)(diskUsage.getDiskWriteBytes()));
}catch(SigarException sigarEx){
log.debug("Disk Usage info load Error : " + sigarEx.getMessage());
}
I used the 'Search' feature in Eclipse many times. ( logs, WORK_DIR, and 4 types of log name, and many others. I am unable to locate the code about logging configuration. :(
My log4j version :
1.2.15
Ok, it seems that there's a solution which might help you. It requires some debugging of static initalization block of org.apache.log4j.LogManager class. This class is responsible for loading logger configuration file. Here's a documention link which thoroughly describes initalization process: link.
Here's an excerpt from a LogManager source file:
String configurationOptionStr = OptionConverter.getSystemProperty(DEFAULT_CONFIGURATION_KEY, null);
String configuratorClassName = OptionConverter.getSystemProperty(CONFIGURATOR_CLASS_KEY, null);
What I'm trying to show you here, is that your logger configuration file might be specified as a JVM option supplied to your application-server. That's why you are not able to determine actual file being used.
Even if this approach fails, I'd recommend you to investigate the appenders list retrieved at run-time. Here's a stackoverflow thread which describes how to do so: link.
I'm using logback-spring.xml in a spring boot project. I want to log all uncaught exceptions to a file. Basically just direct the output from the console to a file. I've tried several variations of logback-spring.xml.
I tried this
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="com.mine" level="WARN" additivity="false">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
</appender-ref>
</root>
</configuration>
with this in my main method SLF4JBridgeHandler.install();
I've tried this from the spring docs
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
this is in my application.yml
logging:
file: C:\dev\assessment-tool\logs\application.log
config: classpath:logback-spring.xml
For these it will log all the start up logging messages but when an exception is thrown and not caught it goes to the console and doesn't show up in the log file. How can I make uncaught exceptions go to a log file?
The problem is on the levels you're assigning to the loggers in the logback-spring.xml file.
According to the logback architecture documentation, (you can check it here) "The effective level for a given logger L, is equal to the first non-null level in its hierarchy, starting at L itself and proceeding upwards in the hierarchy towards the root logger".
You're assigning level "INFO" on your root logger, and level "WARN" on the logger "com.mine". None of them get "called" when there is an exception, ex: logger.error(Exception e).
One solution is assign the level "DEBUG" or "ERROR" to the logger "com.mine" or to the root logger, because they have attached the appender "FILE".
I'm trying to configure logback to print:
- everything (level trace or debug) to the screen
- everything (level trace or debug) to the debugfile
- warnings and above to an error file
My logback.xml config is like this:
...
<logger name="be" level="TRACE">
<appender-ref ref="FILE-AUDIT" />
<appender-ref ref="STDOUT" />
</logger>
<root level="WARN">
<appender-ref ref="FILE-ERROR" />
</root>
However, the error and debug file contain exactly the same, being ALL logging (debug and error). I've already tried to play with the additivity option, but that's apparently not what I need.
The second question is that I use name "be" to have all classes under be.* but actually I want to capture everything there (com.* as well).
Found a solution by adding a filter to the appender:
<appender name="FILE-ERROR"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- deny all events with a level below WARNING -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
Hi I'd like to exclude certain subpackages from being logged by one of my loggers, as they are being logged by another logger. Eg.
com.mysite.app = logger1
com.mysite.app.news = logger2
com.mysite.app.events = logger3
I'd like logger1 to only log anything with com.mysite.app (including com.mysite.app.utilities) not logged by logger2 and logger3. How could I do that?
(help in properties format please, XML format for other's reference for bonus points)
I always used to think that log4j.logger.com.mysite.app = logger1 takes care of logging messages from subpackages too into logger1.
If you really don't want logger2 and logger3's messages from interfering with those of logger1, you need to set their additivity to false.
log4j.additivity.com.mysite.app.news=false
log4j.additivity.com.mysite.app.events=false
Have a try:
log4j.logger.com.mysite.app=info, stdout
log4j.additivity.com.mysite.app=false
log4j.logger.com.mysite.app.news=off, stdout
log4j.additivity.com.mysite.app.news=false
log4j.logger.com.mysite.app.events=off, stdout
log4j.additivity.com.mysite.app.events=false
For XML configuration:
<logger name="com.mysite.app.news" additivity="false">
<appender-ref ref="logger2" />
</logger>
<logger name="com.mysite.app.events" additivity="false">
<appender-ref ref="logger3" />
</logger>