Module id.xfunction

Class XLogger

Object
Logger
XLogger

public class XLogger extends Logger
Using java.util.logging you have to specify location of logging.properties file using -Djava.util.logging.config.file=ABSOLUTE_PATH where ABSOLUTE_PATH is a local file system path. If you want to put it inside of your jar it may be a problem. XLogger helps to overcome this.
  • If java.util.logging.config.file is set and it points to local file system file then XLogger will do nothing.
  • If it points to the resource file then it will load it and initialize JUL with it.
  • If java.util.logging.config.file is not set then it will search for resource /logging.properties and initialize JUL with it.
  • Otherwise it will do nothing

Use it in same way as you would use Logger


 static final Logger LOGGER = XLogger.getLogger(HelloWorld.class);
 LOGGER.log(Level.FINE, "Publishers: {0}", publishers);
 

This class also enhance Logger with methods accepting varargs instead of Object[]. It means that you don't need to provide source class name in each call. Same for info logging methods.

  • Constructor Details

    • XLogger

      protected XLogger(String className)
    • XLogger

      protected XLogger(String className, int hashCode)
  • Method Details

    • getLogger

      public static XLogger getLogger(Class<?> cls)
      Returns Logger with given class name as a logger name.
    • getLogger

      public static XLogger getLogger(String name)
      Returns Logger with given logger name.
    • getLogger

      public static XLogger getLogger(Object obj)
      Returns Logger with given object class name as a logger name. It also stores object hashCode as unique ID and includes it as part of the logging source class name
    • getLogger

      public static XLogger getLogger(Class<?> clazz, TracingToken token)
    • load

      public static void load(String propertyResource)
      Initializes java.util.logging using specified property resource.

      Visible for tests only.

      Parameters:
      propertyResource - absolute path to resource file
    • load

      public static void load()
      Initializes java.util.logging with default settings as described in XLogger

      Allows XLogger explicitly to reset any java.util.logging configuration changes.

    • reset

      public static void reset()
      Reset LogManager to default configuration
    • isLoggable

      public boolean isLoggable(Level level)
      Overrides:
      isLoggable in class Logger
    • log

      public void log(LogRecord record)
      Overrides:
      log in class Logger
    • entering

      public void entering(String sourceMethod)
    • entering

      public void entering(String sourceMethod, Object... params)
    • exiting

      public void exiting(String sourceMethod)
    • exiting

      public void exiting(String sourceMethod, Object result)
      Unfortunately original Logger method does not convert result to String and requires you to call it explicitly and only then pass String result. This method does it for you and converts the result to String and pass it further to Logger.
    • info

      public void info(String msg)
      In java.util.logging to log Level.INFO messages you need explicitly pass the corresponding log Level to log method. This method does it automatically.
      Overrides:
      info in class Logger
    • info

      public void info(String msg, Object... param)
      In java.util.logging to log Level.INFO messages you need explicitly pass the corresponding log Level to log method. This method does it automatically.
    • warning

      public void warning(String msg, Object... param)
      In java.util.logging to log Level.WARNING messages you need explicitly pass the corresponding log Level to log method. This method does it automatically.
    • severe

      public void severe(String msg, Object... param)
      In java.util.logging to log Level.SEVERE messages you need explicitly pass the corresponding log Level to log method. This method does it automatically.
    • severe

      public void severe(String msg, Throwable t)
      In java.util.logging to log Level.SEVERE messages you need explicitly pass the corresponding log Level to log method. This method does it automatically.
    • severe

      public void severe(Throwable t)
      In java.util.logging to log Level.SEVERE messages you need explicitly pass the corresponding log Level to log method. This method does it automatically.
    • fine

      public void fine(String msg, Object... param)
      In java.util.logging to log Level.FINE messages you need explicitly pass the corresponding log Level to log method. This method does it automatically.