• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log file is not created using util.logger

 
Raghu Sha
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to write a log into a file using java.util.logging.
File name should read fom properties file.

Issue is file is not created in D:\TestLogging.log

logger.properties

handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
.level=INFO

myapp.ui.level=ALL
myapp.business.level=CONFIG
myapp.data.level=SEVERE

java.util.logging.ConsoleHandler.level=SEVERE
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

java.util.logging.FileHandler.level=ALL

# Naming style for the output file:
# (The output file is placed in the directory
# defined by the "user.home" System property.)
java.util.logging.FileHandler.pattern=D:\TestLogging.log

# Limiting size of output file in bytes:
java.util.logging.FileHandler.limit=50000

# Number of output files to cycle through, by appending an
# integer to the base file name:
java.util.logging.FileHandler.count=1

# Style of output (Simple or XML):
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

SimpleLogger.java

import java.util.logging.*;

public final class SimpleLogger {

public static void main(String argv[]) {
SimpleLogger thing = new SimpleLogger();
thing.doSomething();
}

public void doSomething() {
fLogger.finest("this is finest");
fLogger.finer("this is finer");
fLogger.fine("this is fine");
fLogger.config("this is config");
fLogger.info("this is info");
fLogger.warning("this is a warning");
fLogger.severe("this is severe");

fLogger.logp(Level.INFO, this.getClass().toString(), "doSomething", "blah");

Throwable ex = new IllegalArgumentException("Some exception text");
fLogger.log(Level.SEVERE, "Some message", ex);
fLogger.exiting(this.getClass().toString(), "doSomething");

System.out.println("user.home dir: " + System.getProperty("user.home") );
}
private static final Logger fLogger =
Logger.getLogger(SimpleLogger.class.getName());
}

Could you please help, any configuration is missed
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to be straight with you, I haven't used the built in logging system in a while but...

Raghu Sha wrote:# Naming style for the output file:
# (The output file is placed in the directory
# defined by the "user.home" System property.)
java.util.logging.FileHandler.pattern=D:\TestLogging.log

The comment on that property says the property is for the naming style for the output file. The style is important because there will likely need to be multiple files for different packages and dates (to prevent any one log file from getting too big and impossible to navigate). The pattern property is not the path where the file is stored. In fact, the comment tells you exactly where the document does get stored.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic