How can I log in from my web application in Tomcat 6

How do I log in from my web application deployed on Tomcat 6? Where should I expect the log to exit (tomcat internal log files, or will another log file be created)? I see a ton of documentation, but it's hard for me to find a direct answer to the above questions. Where should I expect the log to be displayed (currently log4j does not create a log file and it does not appear in my console). I am trying to follow http://www.laliluna.de/articles/log4j-tutorial.html .

### direct log messages to stdout ### log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### file appender log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.maxFileSize=100KB log4j.appender.file.maxBackupIndex=5 log4j.appender.file.File=test.log log4j.appender.file.threshold=info log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n log4j.rootLogger=debug, stdout 

In my application, I define a log object:

 private static org.apache.log4j.Logger log = Logger.getLogger(MyClass.class); log.error("LOGGING!"); 

Thanks for the help.

+4
source share
5 answers

2 things to try:

1: Change test.log to /tmp/test.log so that you know exactly where the file will be filed.

2: Put the log4j.properties configuration file in the apache-tomcat-6.0.x / lib directory along with the log4j-1.2.15.jar file. And you do not have log4j files in your webapps / * / WEB-INF / lib

The way I do it and its work is for me. Here is a useful snippet from my log4j.properties (don't forget to do mk / tmp / logs if you use this configuration)

 log4j.rootLogger=debug, root log4j.appender.root=org.apache.log4j.FileAppender log4j.appender.root.layout = org.apache.log4j.PatternLayout log4j.appender.root.layout.conversionPattern = %d [%t] %-5p %c - %m%n log4j.appender.root.file = /tmp/logs/root.log log4j.appender.root.append = true log4j.category.mside = DEBUG,msideAppender log4j.category.javashare = DEBUG,msideAppender log4j.additivity.mside = false log4j.additivity.mside.msideAppender = false log4j.additivity.javashare = false #Define msideAppender. log4j.appender.msideAppender = org.apache.log4j.RollingFileAppender log4j.appender.msideAppender.MaxFileSize=10MB log4j.appender.msideAppender.MaxBackupIndex=7 log4j.appender.msideAppender.file = /tmp/logs/mside.log log4j.appender.msideAppender.layout = org.apache.log4j.PatternLayout log4j.appender.msideAppender.layout.conversionPattern = %d [%t] %-5p %c - %m%n log4j.appender.msideAppender.append = true 
+4
source

IIRC Tomcat v4 / v5 sends standard output to the catalina.out file, so any log4j output using the console application will also be sent to this file. Not sure if this still applies to newer versions of Tomcat.

+2
source

Your log4j configuration will be raised by log4j if you put it in the classpath of your web application, for example. in WEB-INF / classes /. Make sure your log4j.jar is in WEB-INF / lib.

The output of the Consolidator that you defined, which registers with stdout, will go to $ {CATALINA_BASE} /logs/catalina.out, like any output from stdout Tomcat.

As for RollingFileAppender, you have to determine the right path. If you want the logs of your web application to appear in the Tomcat log directory, change the file for this application to:

 log4j.appender.file.File=${catalina.base}/logs/test.log 
+2
source

BTW, use the system property -Dlog4j.debug. This should tell you where heck log4j sends its output.

In addition, if your tomcat installation is on * nix or if you are running Windows with cygwin installed, you can use the find command to determine which files will be modified immediately after sending the Tomcat HTTP request (which you know you should generate log output)

 cd <your tomcat install> ls -ltr `find . -type f -ls` | tail -10 

This should show you the last 10 files that have been updated or changed. This will not work if your application has files with spaces in the file names.

+1
source

I tried the following path and made sure it works well:

  • put your own log4j.properties place along the way;
  • then update your catalina.sh file under tomcat, add the following line:

    JAVA_OPTS = "- Dlog4j.configuration = file: $ {yourownlog4jpath}"

0
source

Source: https://habr.com/ru/post/1306193/


All Articles