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.
Related
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.
Our app runs on Tomcat 8 and Linux. We have log4j.xml shipped with the war that controls the level of logging for our applications logging. The log4j also defines logging levels for SQL.
In hibernate.cfg.xml, the "hibernate.show_sql" is set to true.
<property name="hibernate.show_sql">true</property>
In $CATALINA_BASE/conf/logging.properties
All references to ConsoleAppender:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
Are removed, so nothing is sent to std out except for the SQL statements.
The: "hibernate.show_sql">true, sends all SQL statements being processed to catalina.out – please note that catalina.out is a file created only on Linux/Unix machines.
I read that "hibernate.show_sql">true, logs the SQL statements at DEBUG level. The problem is that I want to log those statements at ERROR level but don’t know how to control the level?
I read that that level for SQL logging can be controlled by log4j.xml, but changing it in log4j.xml has no effect on how the catalina.out is being logged. Does anyone know how can I control the SQL logging in catalina.out to be only at ERROR level?
Below is log4j.xml.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="mylog" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.base}/logs/mylog.log" />
<param name="Threshold" value="TRACE" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="300MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="it.openutils.log4j.FilteredPatternLayout">
<param name="ConversionPattern"
value="%d{ISO8601} %5p [%t] Executor:%X{Executor} Type:%X{Type} A:%X{Account} C:%X{Campaign} %c{1}:%L - %m%n" />
</layout>
</appender>
<logger name="org.hibernate.SQL" additivity="false">
<level value="ERROR" />
<appender-ref ref="mylog" />
</logger>
<logger name="org.hibernate">
<level value="ERROR"/>
</logger>
<logger name="org.hibernate.jdbc.JDBCContext">
<level value="ERROR"/>
</logger>
<root>
<level value="info" />
<appender-ref ref="mylog" />
</root>
Since I was not able to find anyway to set the level to ERROR for Catalina.out, I decided to turn off the SQL logging all together. So I changed all levels in log4j.xml back to INFO and set this property to false in hibernate.cfg.xml.
<property name="hibernate.show_sql">false</property>
After a while logging, I noticed that there is nothing being logged in Catalina.out unless an error happens, so in this case, the errors and exceptions are being logged into Catalina.out and not the regular SQL statements, which is (almost) something I was trying to achieve at the first place. I do not know why that’s the case thou and where/how those logging levels are defined. But hope that helps somebody.
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>
I want to set up log4j so that all log meessages produced from classes under package com.foo.bar go to bar.log, and all the log meessages produced from classes under package com.bar.blatz go to blatz.log.
Questions
How do I do this using log4j.xml?
I know its possible using property files, but how do I do it using the XML configuration?
This is based on my answer to a similar question:
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- general application log -->
<appender name="BarLogFile" class="org.apache.log4j.FileAppender">
<param name="File" value="bar.log" />
<param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %t [%-40.40c] %x - %m%n"/>
</layout>
</appender>
<!-- additional fooSystem logging -->
<appender name="BlatzLogFile" class="org.apache.log4j.FileAppender">
<param name="File" value="blatz.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %t [%-40.40c] %x - %m%n"/>
</layout>
</appender>
<logger name="com.foo.bar">
<appender-ref ref="BarLogFile"/>
</logger>
<logger name="com.bar.blatz">
<appender-ref ref="BlatzLogFile"/>
</logger>
<root>
<level value="INFO"/>
<!-- no appender, output will be swallowed (I think) -->
</root>
</log4j:configuration>
If you add an appender-ref to the root element, it will also receive com.foo.bar etc messages. You can stop that by specifying 'additivity="false"' on the loggers.
<root>
<level value="INFO"/>
<!-- no appender, output will be swallowed (I think) -->
</root>
We can add appenders here. It will work if the application is using root logger. for example quartz Scheduler API.