LOGGING / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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. […]
LOGGING / NOTES</>↗Logging23 Feb 2009
In this example you’ll see how to add ConsoleHandler to the Logger instance. It is simple, just create an instance of ConsoleHandler and add it to the Logger using the Logger.addHandler() method. package org.kodejava.util.logging; import java.util.logging.Logger; import java.util.logging.ConsoleHandler; import java.util.logging.Level; public class LogConsoleHandler { public static void main(String[] args) { // Obtains Logger instance Logger […]
LOGGING / NOTES</>↗Logging19 Feb 2009
An application log need to be persisted so that we can analyze the log when an error occurred in our application. For this reason we need to write to log into a file. The Logging API provide handlers which helps us to do this. To write log to a file we can use the FileHandler. […]