Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I guess I can chnage pattern by adding the line java.util.logging.ConsoleHandler.pattern, however where to check the pattern information like %u %h etc?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
163 views
Welcome To Ask or Share your Answers For Others

1 Answer

This question has already been answered by somebody, but i want to provide some new information:

Since Java 7 it is possible to configure the output pattern for log messages with the SimpleFormatter.

You can use this property in your logging properties file:

java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n

If you need more information on the pattern syntax have a look here: http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html

The digits in the property value above refer to parameters provided to the formatter. Please refer to the official Java docs for more information: http://docs.oracle.com/javase/7/docs/api/java/util/logging/SimpleFormatter.html

Example configuration file logging.properties:

handlers = java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
# Pattern works since Java 7
java.util.logging.SimpleFormatter.format = [%1$tc] %4$s: %2$s - %5$s %6$s%n

# Configure logging levels
# Available log levels are:
# OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL

# root logger
.level = WARNING

# child logger
org.example.level = ALL

When you call your java program you can specify your configuration file as parameter:

java -Djava.util.logging.config.file=logging.properties -jar myProgram.jar

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...