I want to log into Cassandra db with log4j.
So I write this log4j.xml configuration:
<appender name="DBlog" class="org.apache.log4j.jdbc.JDBCAppender">
<param name="URL" value="jdbc:cassandra://localhost:9160/MyKeyspace" />
<param name="Driver" value="org.apache.cassandra.cql.jdbc.CassandraDriver" />
<param name="User" value="" />
<param name="Password" value="" />
<layout class="..."/>
</appender>
<logger name="logger">
<level value="info"/>
<appender-ref ref="DBlog" />
</logger>
Logging is doing well. But, log4j generates this message:
log4j:WARN No appenders could be found for logger (org.apache.cassandra.cql.jdbc.CassandraDriver).
log4j:WARN Please initialize the log4j system properly.
I don't understand what is wrong.
If anyone knows the answer, please help.
You need to define one more logger:
<logger name="org.apache.cassandra.cql.jdbc">
<level value="info"/>
<appender-ref="DBlog" />
</logger>
And I think it's a good practice to define root logger in any cases.
<root>
<level value="info"/>
<appender-ref ref="DBlog"/>
</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>
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 am trying to log some details in the DB using log4j. I have configured the logging-channel-adapter as the wire-tap.
The required logger is the dbappender but the same is not working.
spring-integration.xml
<int:wire-tap channel="logChannel"/>
<int:logging-channel-adapter id="logChannel" level="INFO" logger-name="AUDIT_the.details" />
log4j.xml
<logger name="AUDIT_the.details">
<level value="INFO" />
<appender-ref ref="asyncAppender" />
</logger>
<appender name="asyncAppender" class="org.apache.log4j.AsyncAppender">
<param name="blocking" value="false" />
<appender-ref ref="dbAppender" />
</appender>
<appender name="dbAppender" class="LoggerTemplate">
<param name="driver" value="oracle.jdbc.OracleDriver" />
<param name="sql"
value="SQL_QUERY" />
<param name="Threshold" value="info" />
</appender>
You have configured a wiretap channel but you also need to put that in some interceptor tag for the channel you want to intercept.Not sure if you have done that as its missing in your post. Below is one example.
<integration:channel id="mydbchannel-to-intercept">
<integration:interceptors>
<int:wire-tap channel="logChannel"/>
</integration:interceptors>
</integration:channel>
I am trying to enable logging of incoming HTTP headers on my server which uses Axis2, is there a way to do it via log4j?
Axis2 uses Apache Commons Logging, a pluggable logging API. Now the question is: which logging library does your server use? If it's log4j, then you probably can make it log the Axis2 traffic — try setting
log4j.logger.org.apache.axis2.transport.http.server.wire=DEBUG
in the log4j.properties file of the application server.
If your server uses other lib, however, redirecting axis output to log4j may involve playing with classloaders as described in Commons Logging FAQ — so that Commons Logging and Log4j are loaded by the same classloader, you'll need to deploy both libraries with your EAR and reverse classloading policy to "parent last". Chances are other libraries from your application won't run with this setting.
I know it is old post, but I would like to share my solution to help other as I just faced the same case recently. I have configured the following in log4j.xml
<appender name="fileout" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="/soapLog/axis2.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%p] %m%n" />
</layout>
</appender>
<logger name="org.apache.axis2.enterprise">
<level value="debug" />
<appender-ref ref="fileout" />
</logger>
<logger name="de.hunsicker.jalopy.io">
<level value="debug" />
<appender-ref ref="fileout" />
</logger>
<logger name="httpclient.wire">
<level value="debug" />
<appender-ref ref="fileout" />
</logger>
<logger name="org.apache.commons.httpclient">
<level value="debug" />
<appender-ref ref="fileout" />
</logger>
<logger name="org.apache.axis2.transport.http.server.wire">
<level value="debug" />
<appender-ref ref="fileout" />
</logger>
Hope this may help.
I'm using log4net v1.2 with a Windows Service App. My RollingFileAppender seems not to work. I'm pasting the logging sections of my service.exe.config below. Can anyone advise where I'm going wrong?
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
.....(lots of other config stuff)
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender,log4net" >
<param name="File" value="D:\\Trinity\\Booking\\OneDay_PostTrade\\logs\\Trinity.log" />
<param name="MaximumFileSize" value="20MB" />
<param name="MaxSizeRollBackups" value="10" />
<param name="StaticLogFileName" value="true" />
<param name="Threshold" value="ALL" />
<param name="RollingStyle" value="Composite" />
<param name="appendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
...(stuff in between)
<root>
<level value="ALL" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="RollingFileAppender" />
</root>
.....(stuff in between)
<logger name="CSFB.PostTradeRulesEngine">
<level value="ALL"/>
</logger>
The user your windows service is running as might not have write permission for the log file.
Another possibility is that you forgot to execute XmlConfigurator.Configure();
try writing:
<log4net debug="true">
it will post all errors to console.
thanks to everyone who responded. I dont know what i changed but my logging has started working fine.
Posting my logging sections. I didnt change anything in the code, except a line in the AssemblyInfo.cs:
[assembly: log4net.Config.Domain(UseDefaultDomain=true)]
Thanks again.:)