LOGGING / CATATAN</>↗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 / CATATAN</>↗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 = […]
LOGGING / CATATAN</>↗Logging01 Mar 2009
Here we demonstrate how to obtain the current level of the Logger instance. The log level will be inherited from the parent logger when the level is not set explicitly . package org.kodejava.util.logging; import java.util.logging.Logger; import java.util.logging.Level; public class LoggerGetLevel { private static Logger logger = Logger.getLogger(LoggerGetLevel.class.getName()); public static void main(String[] args) { LoggerGetLevel demo […]
LOGGING / CATATAN</>↗Logging28 Feb 2009
In this example you see how we can change or set the Logger log level. The log level will tell the Logger which particular log message will be logged. Logger will only record the log message if the level is equal or higher than the Logger level. For instance when the level set to Level.SEVERE, […]
LOGGING / CATATAN</>↗Logging28 Feb 2009
This example give you an example on how to set the Filter of a logger handler. In the code below we implement the Filter on the FileHandler to log only a Level.SEVERE message. Other log level will not be recorded to the file. package org.kodejava.util.logging; import java.util.logging.*; import java.io.IOException; public class LoggerFilter { public static […]
LOGGING / CATATAN</>↗Logging24 Feb 2009
In this example we demonstrate the use of Logger‘s MemoryHandler to log only when some conditions happen in our application, for example when a Level.SEVERE message is logged. We create an instance of MemoryHandler that will delegate the log to FileHandler class, and it logs the last 100 record until a Level.SEVERE message is logged. […]