Home | pfodApps/pfodDevices | WebStringTemplates | Java/J2EE | Unix | Torches | Superannuation | | About Us
 

Forward Logo (image)      

Java GUI Programming Tips and Guidelines
Why is my Java Logging not working.

Also see How to Set up Java Logging which covers capturing console output from Java Logging and Log4J

Introduction

One of the problems with Java logging is that it quietly ignores errors. This means it can be difficult to track down just what is wrong. Is there an error in the configuration file, is the class file missing, is the level set incorrectly or did I just not turn the logging on?

Sample usage

Add Logging_Fcc_2_3withSrc.jar to your classpath (it contains the complete source code, docs and compiled class files)
Put the following line in you code near where it exits
    System.out.println(au.com.forward.logging.Logging.currentConfiguration());
This will print out the current logging configuration to System.out. This code always produces some output so if you don't get any output the code is not being executed. See below for where to put this statement.

Common Java Logging problems

Common problems which Java Logging silently ignores include

 

Logging.currentConfiguration()

To help you track down the errors I have added a static method currentConfiguration() to the au.com.forward.logging.Logging class. This method returns a string describing the current logging configuration. The complete source code, docs and compiled class files are available in this jar file

A sample output, from the following command line, is

java au.com.forward.ExampleLoggingApplication
-- Logging configuration --
 The classpath is '.'
 No java.util.logging.config.class class is set.
 No java.util.logging.config.file file is set.

    There are 1 logging handlers :-
Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

    Currently known loggers are:-
LoggerName:'au.com.forward.ExampleLoggingApplication'
    Level:INFO  set by parent:''
    Filter:none set
    ResourceBundleName: none set 
    Handlers: set by parent:''
             Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

LoggerName:'global'
    Level:INFO  set by parent:''
    Filter:none set
    ResourceBundleName: none set 
    Handlers: set by parent:''
             Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

LoggerName:''
    Level:INFO  
    Filter:none set
    ResourceBundleName: none set 
    Handlers: 
             Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

NOTE: More loggers may be added as classes are loaded by the JVM.

Restarting the application with the command line

java -Djava.util.logging.config.class=DummyClass -Djava.util.logging.config.file=exampleLogging.properties au.com.forward.ExampleLoggingApplication

gives the following output.
Note that the DummyClass class was not found but the logging configuration file was found and the ExampleLoggingApplication class logging level has been set to FINEST.

-- Logging configuration --
 The classpath is '.'
java.util.logging.config.class is set to 'DummyClass'
   An error occured creating this class.  The error was:
java.lang.ClassNotFoundException: DummyClass
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at au.com.forward.logging.Logging.currentConfiguration(Logging.java:234)
        at au.com.forward.ExampleLoggingApplication.main(ExampleLoggingApplication.java:101)

java.util.logging.config.file is set to 'exampleLogging.properties'
      'C:\LoggingWebDist\exampleLogging.properties'
   and this file exists.
  The java.util.logging.config.class failed to load (see above)
    so the settings in the java.util.logging.config.file take effect.

    There are 2 logging handlers :-
Handler:java.util.logging.FileHandler Level:ALL Formatter:au.com.forward.logging.LoggingXMLFormatter
Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

    Currently known loggers are:-
LoggerName:'au.com.forward.ExampleLoggingApplication'
    Level:FINEST  
    Filter:none set
    ResourceBundleName: none set 
    Handlers: set by parent:''
             Handler:java.util.logging.FileHandler Level:ALL Formatter:au.com.forward.logging.LoggingXMLFormatter
             Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

LoggerName:'global'
    Level:SEVERE  set by parent:''
    Filter:none set
    ResourceBundleName: none set 
    Handlers: set by parent:''
             Handler:java.util.logging.FileHandler Level:ALL Formatter:au.com.forward.logging.LoggingXMLFormatter
             Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

LoggerName:''
    Level:SEVERE  
    Filter:none set
    ResourceBundleName: none set 
    Handlers: 
             Handler:java.util.logging.FileHandler Level:ALL Formatter:au.com.forward.logging.LoggingXMLFormatter
             Handler:java.util.logging.ConsoleHandler Level:SEVERE Formatter:au.com.forward.logging.LoggingSimpleFormatter

NOTE: More loggers may be added as classes are loaded by the JVM.

Where to call Logging.currentConfiguration()

As noted above, loggers created in classes are not visable in the current configuration until their class is loaded. This means the best place to call
    System.out.println(au.com.forward.logging.Logging.currentConfiguration());
is at the end of the application main() or in the exit code after all the classes have been loaded.


Forward home page link (image)

Contact Forward Computing and Control by
©Copyright 1996-2017 Forward Computing and Control Pty. Ltd. ACN 003 669 994