Syed, On 8/9/2016 10:08 PM, Syed Mudassir Ahmed wrote: > I am using Log4j in my web app to write the logs to a separate file. > Surprisingly, that log file is not at all getting created. I run > the logger logic as a standalone application and the log file indeed > gets created. I am assuming tomcat is not allowing me to write my > logs to a file. It is simply redirecting all the log messages to > catalina.out. Any suggestions on how to direct my logs to a separate > file and not to catalina.out. > > Thanks, >
Hmm, Works for me . . . <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration PUBLIC 'PUBLIC:-//log4j/log4j Configuration//EN' 'http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc- files/log4j.dtd'> <log4j:configuration> <appender name="FA" class="org.apache.log4j.FileAppender"> <param name="File" value="${catalina.base}/logs/leakrs.log"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n"/> </layout> </appender> <logger name="org.mdeggers.leakrs" additivity="false"> <level value="INFO"/> <appender-ref ref="FA"/> </logger> </log4j:configuration> (sorry for the word wrap for the !DOCTYPE line). Since log4j 1.x was retired in April of 2015, maybe you should move to log4j2. Read the following: https://logging.apache.org/log4j/2.x/manual/webapp.html A (more or less) corresponding log4j2.xml file (different app): <?xml version="1.0" encoding="UTF-8"?> <Configuration> <Appenders> <RollingFile name="FA" immediateFlush="true" fileName="${sys:catalina.base}/logs/logstwo.log" filePattern= "${sys:catalina.base}/logs/logstwo-%d{yyyy-MM-dd}.log.gz"> <PatternLayout> <Pattern>%d %-5p %c.%M:%L - %m%n</Pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy /> </Policies> </RollingFile> </Appenders> <Loggers> <Logger name="org.mdeggers" level="INFO" additivity="false"> <AppenderRef ref="FA"/> </Logger> <Root level="INFO"> <AppenderRef ref="FA"/> </Root> </Loggers> </Configuration> Note, the log4j2.xml does log rotation, as well as compression of the rotated log files. It also logs at a package level one higher than the log4j.xml configuration. The XML file (log4j.xml or log4j2.xml) goes into WEB-INF/classes, or in a JAR file in WEB-INF/lib. The appropriate log4j jar files (different between log4j and log4j2) go in WEB-INF/lib. Quite frankly, your question is very broad and without writing a tutorial it's difficult to answer. I suggest reading the following as well: http://www.catb.org/~esr/faqs/smart-questions.html . . . just my two cents /mde/
signature.asc
Description: OpenPGP digital signature