Last active
September 16, 2018 01:54
-
-
Save rupert-ong/9cfe11114ac0457b6802f1c10378dc45 to your computer and use it in GitHub Desktop.
Java: Logging Hierarchy #java #logging #hierarchy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Specify -Djava.util.logging.config.file=log.properties in the VM arguments | |
# Define parent logger | |
com.ps.handlers=java.util.logging.ConsoleHandler | |
com.ps.level=INFO | |
# Define child logger, its handler and formatter | |
java.util.loggging.FileHandler.level=ALL | |
java.util.logging.FileHandler.pattern=./main_%g.log | |
java.util.logging.SimpleFormatter.format=%1$tc %2$s%n%4$s: %5$s%6$s%n | |
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter | |
com.ps.Main.handlers=java.util.logging.FileHandler | |
com.ps.Main.level=ALL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ps; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
public class Main { | |
// Parent and child logger | |
static Logger pkgLogger = Logger.getLogger("com.ps"); | |
static Logger logger = Logger.getLogger("com.ps.Main"); | |
public static void main(String[] args) { | |
logger.entering("com.ps", "Main"); // Logs to com.ps.Main (Finer level) | |
logger.log(Level.INFO, "We are logging"); // Logs to both loggers | |
logger.exiting("com.ps", "Main"); // Logs to com.ps.Main (Finer level) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handlers specify the output of our log (ConsoleHandler, FileHandler), and Formatters alter the format.