LOGGING / NOTES</>↗Logging17 Mar 2009
In this example we create a rolling or a sequenced of log files. Instead of just limiting the file size (see. How do I limit the size of log file) we can also make the log file to roll. This will prevent a lost to an important log message if we use a single log […]
LOGGING / NOTES</>↗Logging16 Mar 2009
In this example you learn how to limit the size of a log file when using a FileHandler handler. Limiting the log file will prevent the log file to grow wildly without limit. package org.kodejava.util.logging; import java.util.logging.Logger; import java.util.logging.FileHandler; import java.io.IOException; public class LogFileLimit { // The log file size is set to 1 MB. […]
LOGGING / NOTES</>↗Logging12 Mar 2009
To create a custom Formatter we need to extend the java.util.logging.Formatter abstract class and implements the format(LogRecord) method. In the method then we can format the log message stored in the LogRecord to match our need. The java.util.logging.Formatter class also have the getHead(Handler) and getTail(Handler) which can be overridden to add a head and a […]
LOGGING / NOTES</>↗Logging08 Mar 2009
To prevent log records being forwarded to the logger’s parent handlers we can set false the useParentHandlers field using the Logger.setUserParentHandlers(boolean useParentHandlers) method. package org.kodejava.util.logging; import java.util.logging.Logger; import java.util.logging.ConsoleHandler; public class NoParentLogger { public static void main(String[] args) { Logger logger = Logger.getLogger(NoParentLogger.class.getName()); // Do not forward any log messages the logge...
LOGGING / NOTES</>↗Logging07 Mar 2009
In this example we’ll see how to set the formatter for the logger handlers. We set the formatter by calling the Handler.setFormatter() method. In the code below we set a SimpleFormatter for our FileHandler handler and XMLFormatter for the ConsoleHandler handler. This SimpleFormatter format the log in a plain text information while on the other […]
LOGGING / NOTES</>↗Logging03 Mar 2009
In this example we see how we can compare the Level severity between two levels. The Level class has an intValue() method that return the integer value of Level‘s severity. package org.kodejava.util.logging; import java.util.logging.Level; public class LogLevelSeverityCompare { public static void main(String[] args) { Level info = Level.INFO; Level warning = Level.WARNING; Level finest = […]