LOGGING / CATATAN</>↗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 / CATATAN</>↗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. […]
LOGGING / CATATAN</>↗Logging17 Feb 2009
When logging some messages in our application the purpose could be creating a log for debugging purposes. To minimize the impact of these debug message we can use a conditional logging. To do this we need to wrap each call to the logger method with a Logger.isLoggable(Level level) check. The check will ensure that only […]
LOGGING / CATATAN</>↗Logging16 Feb 2009
In this example you can see how we can log an exception when it occurs. In the code below we are trying to parse an invalid date which will give us a ParseException. To log the exception we call the Logger.log() method, passes the logger Level, add some user-friendly message and the Throwable object. package […]
LOGGING / CATATAN</>↗Logging12 Feb 2009
The Logger class provide a setLevel() method to set the logging level. By setting logging to a certain level we can control which message will be logged. To determine or check if a message will be logged we can use the Logger.isLoggable(Level level) method. Let see the example below. package org.kodejava.util.logging; import java.util.logging.Logger; import java.util.logging.Level; […]
LOGGING / CATATAN</>↗Logging09 Feb 2009
Since JDK 1.4 a logging API was introduced into the Java class libraries. This API enables our application to logs some messages to record our application activities. To create an instance of Logger we can call the Logger.getLogger() factory method which will return the available logger for the given namespace, or it will create a […]