Show detailed error in Logger when running Java on server


When "Run on server [^ 1]", when using Logger to output to the console, the" Configuration "level and below were not displayed.


--Set the output destination to a file. I gave up printing to the console. --Set not only setLevel (Level.ALL) of FileHandler but alsosetLevel (Level.ALL) of Logger.


Eclipse 2019-03 (4.11.0) Tomcat 9 Java 11 macOS 10.13.6


It seems that there are some configuration files to output to the console. Article [1] I was able to solve it, but since I used it by overriding Formatter, it is troublesome to use the configuration file. .. So I gave up outputting to the console and output to a file.

Be careful when specifying the log file with a relative path [2].

It seems that the default value of setLevel () in Logger is Level.INFO (information). Let's set it properly.

Source code

public class Log {
	private static final String DEBUG_FILE = "log/test.log";
	private static final Level DEBUG_LEVEL = Level.FINER;
	public static final Logger logger = Logger.getLogger("Test");

	public Log() throws SecurityException, IOException {

		FileHandler debugHandler = new FileHandler(DEBUG_FILE, APPEND);
		debugHandler.setFormatter(new MyFormatter());



	private static void test() {
		File file = new File(DEBUG_FILE);
        if (file.exists()) {
            System.out.println("logfile: " + file.getAbsolutePath());
        } else {
            System.out.println("logfile is not exist");
		logger.finest("log test: FINEST");
		logger.finer("log test: FINER");
		logger.fine("log test: FINE");
		logger.config("log test: CONFIG");"log test: INFO");
		logger.warning("log test: WARNING");
		logger.severe("log test: SEVERE");

By the way, the MyFormatter class is a self-made class that inherits java.util.logging.Formatter.

How to use

new Log();

Initialize with and where you want to output the log

Log.logger.fine("Log message");

I do.


[1] Tomcat, Eclipse and logs [2] Relative path when running Tomcat on Eclipse [3] [Introduction to Java] How to use Logger (explains log level and output destination settings) [4] How to use java.util.logging

[^ 1]: Eclipse + Tomcat app

Recommended Posts

Show detailed error in Logger when running Java on server
Resolve CreateProcess error = 206 when running Java in a Windows environment
Error when running git push heroku master on Heroku
Error in bundle install when running rails new
What I learned when building a server in Java
Error when playing with java
An error occurs when codedeploy-agent is installed in Ubuntu Server 20.04
Symbol not found error when new class in another Java file
Remedy for "A server is already running." Error when running rails s
Avoid character code error in java when using VScode extension RUN-CODE
How to solve the unknown error when using slf4j in Java
Investigation method when the CPU of the server running java is heavy
Error when npm install on Windows 7
Try implementing GraphQL server in Java
<java> When "EXCEPTION_ACCESS_VIOLATION" appears in awt
Error when deploying EC2 on CircleCI
Try running Selenuim 3.141.59 in eclipse (java)
Notes on signal control in Java
Avoid Java encoding errors that occur when running FitGen.exe on Japanese Windows
When seeking multiple in a Java array
I tried running Docker on Windows Server 2019
Kick ShellScript on the server from Java
Error in implementation when implementing Spring validation
Relative path when running tomcat on eclipse
Get history from Zabbix server in Java
Building Java Web Applications on Windows Server 2016
Build Web Application Server (Java) on VPS
Place Java project using database on the server created in VPS so far
407 error when trying to access an HTTPS site in Java via an authenticated proxy
When using a list in Java, java.awt.List comes out and an error occurs
Let's create a TODO application in Java 12 Processing when a request comes in with an unused HttpMethod ・ Processing when an error occurs in the server