log4j:ERROR Attempted to append to closed appender named [eproc-file-out] - log4j

I am getting the error in my server.log file which is given below:
2018-03-23 17:34:38,857 ERROR [stderr] (default task-8) log4j:ERROR Attempted to append to closed appender named [eproc-file-out].
My question is that can anyone explain regarding the category tag and can I use the same appender-ref ref="eproc-file-out" for all the category tags....???
My log4j.xml configuration file is given below:
<appender name="eproc-file-out" class="org.apache.log4j.DailyRollingFileAppender">
<param name="File" value="${jboss.server.log.dir}/eProcurement/eProcurementServerLog.log"/>
<param name="Append" value="true"/>
<param name="DatePattern" value="'.'dd'.txt'"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<category name="com.presentation">
<priority value="DEBUG"/>
<appender-ref ref="eproc-file-out"/>
</category>
<category name="com.service">
<priority value="DEBUG"/>
<appender-ref ref="eproc-file-out"/>
</category>
<category name="com.dao">
<priority value="DEBUG"/>
<appender-ref ref="eproc-file-out"/>
</category>
<category name="org.apache">
<priority value="DEBUG"/>
<appender-ref ref="eproc-file-out"/>
</category>
<category name="org.springframework">
<priority value="DEBUG"/>
<appender-ref ref="eproc-file-out"/>
</category>
<category name="com.metaparadigm">
<priority value="ERROR"/>
<appender-ref ref="eproc-file-out"/>
</category>
<root level="debug">
<appender-ref ref="eproc-file-out"/>
</root>
I did google as well as referred to StackOverflow for this error but I didn't found the solution for my question regarding category tag.
Any help is appreciated!
Thanks

From log4j manual:
public class Category
This class has been deprecated and replaced by the Logger subclass. It will be kept around to preserve backward compatibility until mid 2003.
Logger is a subclass of Category, i.e. it extends Category. In other words, a logger is a category...
...
There is absolutely no need for new client code to use or refer to the Category class. Whenever possible, please avoid referring to it or using it.

Related

Weblogic, log4j and log4jdbc, log in file but not in console

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?

Prevent Log4Net from writing to all log files

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 don't understand why this log4j.xml is wrong

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>

log4j:ERROR Attempted to append to closed appender named [..]

I am getting following errors on my console repeatedly
log4j:ERROR Attempted to append to closed appender named [ConsoleAppender].
log4j:ERROR Attempted to append to closed appender named [FixedWindowRollingFile].
used log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender class="org.apache.log4j.rolling.RollingFileAppender" name="FixedWindowRollingFile">
<param name="Append" value="true"/>
<param name="ImmediateFlush" value="true"/>
<rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
<param name="fileNamePattern" value="logs/StandardizeAccountService.%i.log"/>
<param name="minIndex" value="1"/>
<param name="maxIndex" value="10"/>
</rollingPolicy>
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="MaxFileSize" value="1002400"/>
</triggeringPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %p %c{1}:%L - %m%n"/>
</layout>
</appender>
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.SimpleLayout"/>
</appender>
<logger name="com.arosys" additivity="false" >
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="FixedWindowRollingFile"/>
</logger>
<root>
<priority value="INFO"/>
<appender-ref ref="ConsoleAppender"/>
<appender-ref ref="FixedWindowRollingFile"/>
</root>
</log4j:configuration>
please help me where the problem.
I got the same error:
log4j:ERROR Attempted to append to closed appender named [rollingFileAppender].
In my log4j.xml
I have two loggers with the same name like below
<logger name="java.sql.PreparedStatement" additivity="false">
<level value="INFO"/>
<appender-ref ref="rollingFileAppender"/>
</logger>
<logger name="java.sql.PreparedStatement">
<level value="INFO"/>
<appender-ref ref="rollingFileAppender"/>
</logger>
I removed the duplicate, it worked.
I've answered similar question here: https://stackoverflow.com/a/9973283/340290
In my case, I've two log4j.properties available to the Log4J: one via placing it in classpath and other being loaded programmatically (using PropertyConfigurator.configure(..)).
And in the two files, I've ConsoleAppender registered with same name stdout and used for same category twice (one per each properties file). Removing config or the properties file solved my issue.
One could overwrite the configuration using:
BasicConfigurator.resetConfiguration();
PropertyConfigurator.configure(props);
Just to clarify because I was mislead by MaDa answer, additivity=false redirects the output to another place than the default (root logger) and NOT to the default.
See http://logging.apache.org/log4j/1.2/manual.html chapter "Appenders and Layouts"
This may also mean that you already have your server running, and you're trying to run it again. The second instance can't write to the log file because it's already open in your server.
solution: check to see if your server is already running, and restart it if neccessary.
In my case, I added by mistake 2 "root" elements.
I'm not saying this is the cause of the behaviour you describe (but it might), but this part:
<logger name="com.arosys" additivity="false" >
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="FixedWindowRollingFile"/>
</logger>
is pointless. Normally, you'd set a non-additive logger to redirect it somewhere else than the default place (your root logger), but you still send the output to the default place. You might as well delete this fragment.

Apache commons HTTPClient and log4j.xml

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>

Resources