my dog learned polymorphism*
The moose likes Java in General and the fly likes Log file is not created using util.logger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Log file is not created using util.logger" Watch "Log file is not created using util.logger" New topic
Author

Log file is not created using util.logger

Raghu Sha
Ranch Hand

Joined: Feb 02, 2013
Posts: 122
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

Joined: Jan 28, 2003
Posts: 4167
    
  21

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.


Steve
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Log file is not created using util.logger
 
Similar Threads
java.util.Logging configuration
java.util.logging.FileHandler
GWT Logging
How could I write logs (using java.util.logging) to different file based on differet package?
java.util.Logging configuration...