Syed, Please do not top post. See:
http://tomcat.apache.org/lists.html#tomcat-users item 6. My responses are inline. On 8/10/2016 1:43 AM, Syed Mudassir Ahmed wrote: > Mark, > Thanks for the response. > Indeed I am using Log4j-2. Below is my xml file: > > <?xml version="1.0" encoding="UTF-8"?> > <configuration status="warn" name="SSP_App" packages=""> > <appenders> > <RollingFile name="LogFile" fileName="/home/syed/logs/ssp-log.txt" > > filePattern="/home/syed/logs/ssp-log-%d{MM-dd-yyyy}-%i.txt"> > <PatternLayout> > <pattern>date:%d, millisecs:%r, level:%p, logger:%c, thread:[%t], > file:%F, method:%M, line:%L, message:%m%n%n</pattern> > </PatternLayout> > <Policies> > <SizeBasedTriggeringPolicy size="50 MB"/> > </Policies> > <DefaultRolloverStrategy max="100"/> > </RollingFile> > </appenders> > <loggers> > <logger name="SSPLogger" level="ALL" additivity="false"> > <appender-ref ref="LogFile"/> > </logger> > <root level="warn"> > <appender-ref ref="LogFile"/> > </root> > </loggers> > </configuration> You really need to read the log4j2 documentation. In particular, pay attention to the logger documentation. > > And in my web app, I have the following statement that will set the system > property to where the above file is located at: > > System.setProperty("log4j.configurationFile", "file://" + rootPath + > "/log4j-2.xml"); You really need to read the link I gave you on how log4j2 is configured with web applications. Again, the link is: https://logging.apache.org/log4j/2.x/manual/webapp.html Follow it slavishly until you get things working. You really need to follow the documentation on where to place log4j2.xml and how that file is found. http://logging.apache.org/log4j/2.x/manual/configuration.html In particular, pay attention to Automatic Configuration, item 9. I recommend this until you do a little more reading / research, and understand how things work. That's why I recommended to place log4j2.xml in WEB-INF/classes or in a JAR file in WEB-INF/lib. It's then on the web application classpath. No other configuration is necessary. In particular, pay attention to what happens when you do not configure log4j2 correctly, notably Automatic Configuration, item 10. 10. If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console. This will dump your log output to the console, which ends up in catalina.out when running in Tomcat. > > > Thanks, > > > On Wed, Aug 10, 2016 at 11:59 AM, Mark Eggers <its_toas...@yahoo.com.invalid >> wrote: > >> 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