Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simplest way to log to tomcat catalina.out

What is the simplest way to write logs to tomcat/catalina.out? I have tried System.out.print() and System.err.print() is working fine.

I just want to know if there are better options to use despite of sysout and syserr?

like image 982
tokhi Avatar asked Nov 12 '13 15:11

tokhi


People also ask

How do you get out of Catalina?

By default, the catalina. out file is located in the logs directory under Tomcat's root directory. For example, /opt/netiq/idm/apps/tomcat/logs/catalina. out.

What is Tomcat Catalina log?

Each server instance contains its own Catalina. This file is located in the logs directory below the Tomcat root directory. This log is the system's output log, which also consists of standard error messages. These files are saved daily (MM-DD-YYYY) with the date appended to the name of the data.


2 Answers

import java.util.logging.*

Logger.getLogger (YourClass.class.getName()).log(Level.WARNING, e.getMessage(), e);
Logger.getLogger (YourClass.class.getName()).log(Level.INFO, "hello world");
like image 56
user455497 Avatar answered Sep 28 '22 18:09

user455497


Your Logging

For your own logging (logging items generated by your own servlet code), Simple Logging Facade for Java (SLF4J) is the modern way. This interface acts as a façade to work with any of several pluggable implementations. Those implementations include the java.util.logging tool bundled with Java, log4j, Logback, and more.

Logback is the one you should look at. Created by the man who years ago created the famous log4j. Logback is meant to be the successor to log4j. The same man also created SLF4J as a way to prevent you from getting locked into any one logging framework.

Your servlet code ↔ SLF4J ↔ Logback ↔ logs

You can configure LogBack in a variety of ways to suit your needs. You can write to text files, send the logging items to a database, and more.

Tomcat’s Logging

Besides your own logging, there is the question of the logging performed by Tomcat itself, to track every incoming request.

Tomcat performs such logging through a Valve. By default, those logging items are simply written to a text file. You may want to do more than that.

Logback provides an extra module, logback-access for use with both the servlet containers Tomcat from Apache & Jetty from Eclipse. The module logback-access is an extension of Tomcat's Valve. By extending Valve, you can replace the default behavior. You can send Tomcat’s own logging items to your Logback infrastructure (files, database records, etc.).

like image 22
Basil Bourque Avatar answered Sep 28 '22 18:09

Basil Bourque