I am using Java 6. I have created a custom formatter which creates only the time and the message, but it always prints null class name and method name and the log level besides the time and the message in two lines:
Mar 8, 2015 6:48:09 PM null null
ALL: This is a message
Also, the log files generated are in the following format, where I expected it to start with xxx.log.0 first, once it is full, then xxx.log.1, but it generated all 10 files at the same time.
xxxx.log.0.9
xxxx.log.0.8
xxxx.log.0.7
xxxx.log.0.6
xxxx.log.0.5
xxxx.log.0.4
xxxx.log.0.3
Can someone let me know how I can log only the time and the message and how I correct the log file extensions? Much appreciated!
public class MyFormatter extends Formatter {
public String format(LogRecord record)
{
String recordStr = new Date() + " " + formatMessage(record)
return recordStr;
}
}
The code which uses MyFormatter:
Logger fileLogger = Logger.getLogger(xxxx.class.getPackage().getName());
FileHandler handler = new FileHandler(pattern, limit, numLogFiles, true);
MyFormatter formatter = new MyFormatter();
handler.setFormatter(formatter);
fileLogger.addHandler(handler);
Level logLevel = java.util.logging.Level.ALL;
fileLogger.log(new LogRecord(logLevel, "This is a message"));