Class LogHelper

java.lang.Object
com.gigaspaces.logger.LogHelper

public class LogHelper extends Object
GS-8802 , GS-9973 , GS-10078
A logging helper class used to avoid a deadlock situation when java.util.logging is initializing, while it is also being referenced by utility classes.
The RollingFileHandler resolves its PID, host, and homedir properties by calling utility classes, which also try to reference a Logger using Logger.getLogger(String).
This causes a deadlock in JDK logging, since our custom handler is already called after holding a lock on LogManager class and it is trying to also get a lock on Logger class when calling Logger.getLogger(String) from utility classes.
When another thread calls Logger.getLogger(String) it in turn calls LogManager.demandLogger(..) which locks LogManager on a call to LogManager.getLogger(String).
Deadlock:
lock [LogManager.class] -> LogManager.initializeGlobalHandlers() -> RollingFileHandler.resolveProperty(..) -> wait to lock [Logger.class] on call to Logger.getLogger(..)
lock [Logger.class] -> Logger.getLogger() -> LogManager.demandLogger() -> wait to lock [LogManager.class] on call to LogManager.getLogger()
This helper class is intended to be called by utility classes which need to log messages. We go through LogManager.getLogger(String) to avoid the deadlock. It may return null if not yet initialized, in such a case we try to flush it to system.out/err.
Since:
9.0.0
Author:
moran
  • Field Details

    • ENABLED

      public static final boolean ENABLED
  • Constructor Details

    • LogHelper

      public LogHelper()
  • Method Details

    • log

      public static boolean log(String logName, Level level, String message, Throwable thrown)
      log the message under the logName and level. if logger is null tries to log to system.out/err
      Returns:
      true if logged to log or system.out/err, false otherwise.
    • println

      public static void println(String logName, Level level, String message)
    • println

      public static void println(String logName, Level level, String message, Throwable t)