Class GlobalLog

java.lang.Object
com.pnfsoftware.jeb.util.logging.GlobalLog

public class GlobalLog extends Object
Global logging facility used by JEB. This class offers methods to create per-class loggers. Upon initialization, a JEB client should add destination streams and buffers.

Implementation note: The official RCP client implementation provided with JEB registers stdout as well as the UI console window as destinations.

This class is thread-safe. However, ILogger instances returned by getLogger() are not thread-safe.

How to use:

 import com.pnfsoftware.jeb.util.logging.ILogger;
 import com.pnfsoftware.jeb.util.loggingg.GlobalLog;
 
 class Xyz {
     private static final ILogger logger = GlobalLog.getLogger(Xyz.class);
     ...
 }
 
  • Field Details

    • LEVEL_NAMES

      public static final List<String> LEVEL_NAMES
    • LEVEL_ALL

      public static final int LEVEL_ALL
      See Also:
    • LEVEL_DISABLED

      public static final int LEVEL_DISABLED
      See Also:
    • LEVEL_ALWAYS_ON

      public static final int LEVEL_ALWAYS_ON
      See Also:
    • LEVEL_TRACE

      public static final int LEVEL_TRACE
      See Also:
    • LEVEL_DEBUG

      public static final int LEVEL_DEBUG
      See Also:
    • LEVEL_INFO

      public static final int LEVEL_INFO
      See Also:
    • LEVEL_WARN

      public static final int LEVEL_WARN
      See Also:
    • LEVEL_ERROR

      public static final int LEVEL_ERROR
      See Also:
    • LEVEL_INTERNAL

      public static final int LEVEL_INTERNAL
      Reserved for internal use
      See Also:
    • LEVEL_CATCHING

      public static final int LEVEL_CATCHING
      Special level used to log exception related data such as stack traces. Messages above or equal to this level are never neutered. Eg, disabling a logger will not disable CATCHING messages to go through.
      See Also:
    • LEVEL_STATUS

      public static final int LEVEL_STATUS
      special log level indicating a status message; logs with that status will not be directed to the regular sinks
      See Also:
    • STANDARD_CUTOFF_LEVEL

      public static final int STANDARD_CUTOFF_LEVEL
    • prefixWithLevel

      public static boolean prefixWithLevel
  • Constructor Details

    • GlobalLog

      public GlobalLog()
  • Method Details

    • addDestinationStream

      public static StreamSink addDestinationStream(OutputStream out)
      Add a destination stream to the list of log message recipients.
      Parameters:
      out - a destination stream
      Returns:
      the sink
    • removeDestinationStream

      public static StreamSink removeDestinationStream(OutputStream out)
      Remove a destination stream.
      Parameters:
      out - the destination stream
      Returns:
      the sink
    • getDestinationStreams

      public static List<StreamSink> getDestinationStreams()
      Get the list of registered stream sinks.
      Returns:
      the list of stream sinks
    • addDestinationBuffer

      public static BufferSink addDestinationBuffer(List<CharSequence> buffer)
      Add a destination buffer to the list of log message recipients. The list implementation must be thread-safe: it should be an object returned by Collections.synchronizedList()
      Parameters:
      buffer - the thread-safe buffer
      Returns:
      the sink
    • removeDestinationBuffer

      public static BufferSink removeDestinationBuffer(List<CharSequence> buffer)
      Remove a destination buffer.
      Parameters:
      buffer - the destination buffer
      Returns:
      the sink
    • getDestinationBuffers

      public static List<BufferSink> getDestinationBuffers()
      Get the list of registered buffer sinks.
      Returns:
      the list of buffer sinks
    • getRegularSinks

      public static List<Sink<?>> getRegularSinks()
      Get a list of the regular (= non status) sinks.
      Returns:
    • addStatusSink

      public static void addStatusSink(LogStatusSink sink)
      Register a status sink. Those sinks receive only logs having the special level LEVEL_STATUS.
      Parameters:
      sink -
    • removeStatusSink

      public static void removeStatusSink(LogStatusSink sink)
      Unregister a status sink.
      Parameters:
      sink -
    • getStatusSinks

      public static List<LogStatusSink> getStatusSinks()
      Returns:
      the list of status sinks
    • setCutoffLevel

      public static int setCutoffLevel(int cutoffLevel)
      Parameters:
      cutoffLevel - new level
      Returns:
      the previous level
    • getCutoffLevel

      public static int getCutoffLevel()
      Returns:
    • setLevelForNewLoggers

      public static int setLevelForNewLoggers(int level)
      Set the default logging level
      Parameters:
      level - the default logging level
      Returns:
    • setLevelForNewLoggers

      public static int setLevelForNewLoggers(int level, boolean updateExistingLoggers)
      Parameters:
      level -
      updateExistingLoggers -
    • setGlobalFilter

      public static void setGlobalFilter(boolean mute)
    • addGlobalFilter

      public static void addGlobalFilter(String pattern, int requiredLevel)
    • removeGlobalFilter

      public static void removeGlobalFilter(String pattern)
    • clearGlobalFilters

      public static void clearGlobalFilters()
    • isGloballyDisabled

      public static boolean isGloballyDisabled(ILogger logger)
    • getEnabledLevel

      public static int getEnabledLevel()
      Get the default logging level.
      Returns:
      the default logging level
    • getLogger

      public static ILogger getLogger()
      Create or retrieve the anonymous logger. If created, the logging level is set to the default global logging level.
      Returns:
      the anonymous logger
    • status

      public static void status(String format, Object... params)
      Convenience method for getLogger().status(...).
      Parameters:
      format -
      params -
    • getLogger

      public static ILogger getLogger(Class<?> clazz)
      Create or retrieve a logger attached to and named after a given class. If created, the logging level is set to the default global logging level.
      Parameters:
      clazz - class reference
      Returns:
      the logger
    • getLogger

      public static ILogger getLogger(Class<?> clazz, int level)
      Create or retrieve a logger attached to and named after a given class.
      Parameters:
      clazz - class reference
      level - the cut-off level
      Returns:
      the logger
    • getLogger

      public static ILogger getLogger(String name, int level)
      Create or retrieve a named logger.
      Parameters:
      name - logger name
      level - the cut-off level
      Returns:
      the logger
    • getInternalLogger

      public static ILogger getInternalLogger(Class<?> clazz)
      Create or retrieve an internal logger. INTERNAL USAGE ONLY.
      Parameters:
      clazz -
      Returns:
    • catching

      public static void catching(ILogger logger, Throwable t)
    • catching

      public static void catching(ILogger logger, Throwable t, String message)
    • catchingDebug

      public static void catchingDebug(ILogger logger, Throwable t)
    • catchingDebug

      public static void catchingDebug(ILogger logger, Throwable t, String message)
    • parseLevel

      public static int parseLevel(String s)
      Parse a log level name (or number) to a log level integer usable by Logger objects. On error, this method returns a negative value. Negative value are illegal log levels.
      Parameters:
      s - a log level name or integer as a string
      Returns:
      integer log level, a negative value on error
    • levelToString

      public static String levelToString(int level)
    • getPrefixLetterForLevel

      public static char getPrefixLetterForLevel(int level)
      Retrieve the prefix letter associated to the provided log level.
      Parameters:
      level - log level
      Returns:
      a letter describing the level; 0 on failure
    • getLevelFromPrefixLetter

      public static int getLevelFromPrefixLetter(char ch)
      Retrieve the log level associated to the provided prefix letter.
      Parameters:
      ch - prefix letter
      Returns:
      log level matching the prefix character; negative value on error