I'm using Apache commons HTTPClient with Apache Axis 1.5 and I'm trying to log the messages exchanged when making Web Service calls by enabling org.apache.commons.httpclient to DEBUG and httpclient.wire to DEBUG. However, this doesn't work. Mentioned below is my log4j.xml - can someone help me?
Thanks
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="rolling" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="test.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c:%L - %m%n"/>
</layout>
</appender>
<logger name="org.apache.commons.httpclient">
<level value="DEBUG"/>
</logger>
<logger name="httpclient.wire">
<level value="DEBUG"/>
</logger>
<root>
<level value="DEBUG" />
<appender-ref ref="rolling"/>
</root>
</log4j:configuration>
You need to have the log level set at ALL, not DEBUG
<logger name="httpclient.wire">
<level value="ALL"/>
</logger>
Try putting a priority value set to DEBUG to your <root> node in log4j.xml
<root>
<level value="DEBUG" />
<priority value="DEBUG" />
<appender-ref ref="rolling"/>
</root>
Related
I have a old project which use log4j(not log4j2),it will print file name and line number.
2017-10-21 17:08:54,198 INFO [com.fudy.log4j.PerformanceLogger.info:11
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c.%M:%L] : %m%n" />
</layout>
</appender>
after I add AsyncAppender to log4j.xml
<logger name="com.fudy.log4j.PerformanceLogger" additivity="false">
<level value="DEBUG" />
<appender-ref ref="async" />
</logger>
it print ? instead of method name and linenumber:
2017-10-21 17:24:17,909 INFO [com.fudy.log4j.PerformanceLogger.?:?
after googled, all solution is to add includeLocation in log4j2, is there any solution for logj4 1.x
I found the solution for log4j 1.x
<appender name="async" class="org.apache.log4j.AsyncAppender">
<param name="BufferSize" value="256"/>
<param name="LocationInfo" value="true"/> <!-- add this one -->
<appender-ref ref="console"/>
</appender>
In Weblogic, using log4jdbc, I need to log queries (using org.jdbcdslog.StatementLogger) only in a specific file but not in console.
I tried to start Weblogic with this parameter
-Dlog4j.configuration=file:%LOG4JDBC_HOME%\log4j.xml
This is the content of log4.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG" />
<param name="File" value="./logs/aladin.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss} %-5p %-30.30c %m%n" />
</layout>
</appender>
<category name="org.jdbcdslog.StatementLogger">
<priority value="INFO" />
<appender-ref ref="fileAppender" />
</category>
<category name="org.jdbcdslog.ResultSetLogger">
<priority value="FATAL" />
<appender-ref ref="fileAppender" />
</category>
<root>
<level value="DEBUG" />
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
The problem is that in console I see either org.jdbcdslog.StatementLogger and org.jdbcdslog.ResultSetLogger logged at INFO level, in aladin.log (the only file I'd like to log in) I don't see any log of org.jdbcdslog.StatementLogger and org.jdbcdslog.ResultSetLogger classes.
Is there a way to log these two classes only in aladin.log and not in console?
I've got the following configuration using log4net. The problem is that the logger in my C# code is now logging the errors into the two log files. I've got two different service classes in the same windows service. I initialize the logger in one service using this line:
private static readonly ILog _logger = LogManager.GetLogger(typeof(EmployeeImportService));
But when this service runs and logs, it's writing to both log files.
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="C:\Temp\HRFiles\Sharp\Log\Log.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<appender name="OvertimeLogFileAppender" type="log4net.Appender.FileAppender">
<param name="File" value="C:\Temp\HRFiles\YTD\Log\Log.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c %m%n" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="OvertimeLogFileAppender" />
</root>
</log4net>
How do I configure it so that each service writes to it's own log file? I read that the logger tag in the configuration has an additivity attribute that solves this problem but I have no logger element in my configuration.
You can have two separate loggers, and define which appenders each logger will use in the configuration: you do have to declare additivity=false or else the loggers inherit the appenders from the root logger.
So, with made-up names:
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="OvertimeLogFileAppender" />
</root>
<logger name="Company.Project.EmployeeImportService" additivity="false">
<appender-ref ref="LogFileAppender" />
</logger>
<logger name="Company.Project.EmployeeOvertimeService" additivity="false">
<appender-ref ref="OvertimeLogFileAppender" />
</logger>
Then in your service classes you get the approppriate logger:
// General log - EmployeeImportService
ILog logger = LogManager.GetLogger(typeof(EmployeeImportService));
// Log overtime - EmployeeOvertimeService
ILog logger = LogManager.GetLogger(typeof(EmployeeOvertimeService));
Oups yes I did a mistake. But it quiet the same. You have to create filter in each appender node
<filter type="log4net.Filter.LoggerMatchFilter">
<!-- allows this sub-namespace to be logged... -->
<loggerToMatch value="EmployeeImportService" />
</filter>
I'm new to log4j and trying to use it in a project. For some reason the info won't get displayed on the console. It only works when i change it to logger.error(). This is only happening in the userServiceImpl class the other classes like Controllers are fine.
This is the log4j.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="false"
xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- This default ConsoleAppender is used to log all NON perf4j messages
to System.out -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss} %5p %c{1} - %m%n" />
</layout>
</appender>
<!-- The root logger sends all log statements EXCEPT those sent to the perf4j
logger to System.out. -->
<root>
<level value="ERROR" />
<appender-ref ref="console" />
</root>
<logger name="com.click.heal.controller" additivity="false" >
<level value="INFO" />
<appender-ref ref="console"/>
</logger>
<logger name="com.click.heal.service" additivity="true" >
<level value="INFO" />
<appender-ref ref="console"/>
</logger>
</log4j:configuration>
Your root category is at ERROR level. Anything that doesn't fall under one of your other two loggers will fall under root, and will only log at ERROR level. If you change your root level to INFO, I bet it logs, right? Not saying that's what you want, but it would be a clue that your UserServiceImpl class is logging under root right now.
EDIT
Try turning additivity to false on your logger for the service package. additivity means the messages propogate to the parent, and since the parent is root and root logs to the same console appender, it seems likely that this is causing the problem.
I have two appenders, file and console, in my project. I would like to configure my application to perform as such:
all loggers with name "my.app.*":
1. log events DEBUG and higher to fileA
2. log events DEBUG and higher to fileB
all other loggers:
1. log events WARN and higher to fileA
2. log events DEBUG and higher to fileB
Ideally, the configuration would look something like this:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="fileA" class="org.apache.log4j.FileAppender">
<!-- configuration -->
</appender>
<appender name="fileB" class="org.apache.log4j.FileAppender">
<!-- configuration -->
</appender>
<logger name="my.app" additivity="false">
<level="DEBUG"/>
<appender-ref ref="fileA"/>
</logger>
<logger name="" additivity="true">
<level="DEBUG"/>
<appender-ref ref="fileB"/>
</logger>
<root>
<level="WARN"/>
<appender-ref ref="fileA"/>
</root>
</log4j>
However, this setup causes loggers named "my.app" to only log to console, and all other loggers to log to console on WARN and above. Essentially, <logger name=""> is being ignored. Is there another way to emulate this behavior with log4j?
PS. I apologize for the poor formatting, really struggling to get this to work tonight :/
You need:
<logger name="my.app" additivity="false">
<level="DEBUG"/>
<appender-ref ref="console"/>
<appender-ref ref="file"/>
</logger>
<root>
<appender-ref ref="console-warn"/>
<appender-ref ref="file-debug"/>
</root>
For the root-appender you need two new console/file appenders, that have the desired level restrictions.
<appender name="file-debug" class="org.apache.log4j.FileAppender">
<param name="Threshold" value="DEBUG"/>
</appender>
<appender name="console-warn" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="WARN"/>
</appender>