Package com.pnfsoftware.jeb.util.logging
Class GlobalLog
java.lang.Object
com.pnfsoftware.jeb.util.logging.GlobalLog
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.logging.GlobalLog;
class Xyz {
private static final ILogger logger = GlobalLog.getLogger(Xyz.class);
...
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLog level allowing all messages.static final intThreshold for messages that bypass regular level filtering.static final intSpecial level used to log exception related data such as stack traces.static final intDebug log level.static final intLog level disabling regular messages.static final intError log level.static final intInformation log level.static final intReserved for internal useLog level names, ordered from least to most severe regular level.static final intspecial log level indicating a status message; logs with that status will not be directed to the regular sinksstatic final intTrace log level.static final intWarning log level.static booleanTrue to prefix regular log messages with their level letter.static final intStandard global cutoff level for the current build type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferSinkaddDestinationBuffer(List<CharSequence> buffer) Add a destination buffer to the list of log message recipients.static StreamSinkAdd a destination stream to the list of log message recipients.static voidaddGlobalFilter(String pattern, int requiredLevel) Add or replace a global filter.static voidaddStatusSink(LogStatusSink sink) Register a status sink.static voidLog an exception's stack trace.static voidLog an exception's stack trace with an optional message.static voidcatchingDebug(ILogger logger, Throwable t) Log an exception's stack trace at debug level.static voidcatchingDebug(ILogger logger, Throwable t, String message) Log an exception's stack trace at debug level with an optional message.static voidRemove all global filters.static intGet the global cutoff level.static List<BufferSink> Get the list of registered buffer sinks.static List<StreamSink> Get the list of registered stream sinks.static intGet the default logging level.static ILoggergetInternalLogger(Class<?> clazz) Create or retrieve an internal logger.static intgetLevelFromPrefixLetter(char ch) Retrieve the log level associated to the provided prefix letter.static ILoggerCreate or retrieve the anonymous logger.static ILoggerCreate or retrieve a logger attached to and named after a given class.static ILoggerCreate or retrieve a logger attached to and named after a given class.static ILoggerCreate or retrieve a named logger.static chargetPrefixLetterForLevel(int level) Retrieve the prefix letter associated to the provided log level.Get a list of the regular (= non status) sinks.static List<LogStatusSink> Get the registered status sinks.static booleanisFilteredOut(ILogger logger, int messageLevel) Determine whether a message at a given level sent to a logger should be processed or ignored, based onglobal filters.static booleanisGloballyDisabled(ILogger logger) Deprecated.static StringlevelToString(int level) Convert a log level to a display string.static intparseLevel(String s) Parse a log level name (or number) to a log level integer usable by Logger objects.static BufferSinkremoveDestinationBuffer(List<CharSequence> buffer) Remove a destination buffer.static StreamSinkRemove a destination stream.static voidremoveGlobalFilter(String pattern) Remove a global filter.static voidUnregister a status sink.static intsetCutoffLevel(int cutoffLevel) Set the global cutoff level.static voidsetGlobalFilter(boolean mute) Enable or disable a global mute filter.static intsetLevelForNewLoggers(int level) Set the default logging level.static intsetLevelForNewLoggers(int level, boolean updateExistingLoggers) Set the default logging level for newly created loggers.static voidConvenience method forgetLogger().status(...).
-
Field Details
-
LEVEL_NAMES
Log level names, ordered from least to most severe regular level. -
LEVEL_ALL
public static final int LEVEL_ALLLog level allowing all messages.- See Also:
-
LEVEL_DISABLED
public static final int LEVEL_DISABLEDLog level disabling regular messages.- See Also:
-
LEVEL_ALWAYS_ON
public static final int LEVEL_ALWAYS_ONThreshold for messages that bypass regular level filtering.- See Also:
-
LEVEL_TRACE
public static final int LEVEL_TRACETrace log level.- See Also:
-
LEVEL_DEBUG
public static final int LEVEL_DEBUGDebug log level.- See Also:
-
LEVEL_INFO
public static final int LEVEL_INFOInformation log level.- See Also:
-
LEVEL_WARN
public static final int LEVEL_WARNWarning log level.- See Also:
-
LEVEL_ERROR
public static final int LEVEL_ERRORError log level.- See Also:
-
LEVEL_INTERNAL
public static final int LEVEL_INTERNALReserved for internal use- See Also:
-
LEVEL_CATCHING
public static final int LEVEL_CATCHINGSpecial 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_STATUSspecial 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_LEVELStandard global cutoff level for the current build type. -
prefixWithLevel
public static boolean prefixWithLevelTrue to prefix regular log messages with their level letter.
-
-
Constructor Details
-
GlobalLog
public GlobalLog()
-
-
Method Details
-
addDestinationStream
Add a destination stream to the list of log message recipients.- Parameters:
out- a destination stream- Returns:
- the sink
-
removeDestinationStream
Remove a destination stream.- Parameters:
out- the destination stream- Returns:
- the sink
-
getDestinationStreams
Get the list of registered stream sinks.- Returns:
- the list of stream sinks
-
addDestinationBuffer
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
Remove a destination buffer.- Parameters:
buffer- the destination buffer- Returns:
- the sink
-
getDestinationBuffers
Get the list of registered buffer sinks.- Returns:
- the list of buffer sinks
-
getRegularSinks
Get a list of the regular (= non status) sinks.- Returns:
- a new list containing all regular sinks
-
addStatusSink
Register a status sink. Those sinks receive only logs having the special levelLEVEL_STATUS.- Parameters:
sink- status sink to add
-
removeStatusSink
Unregister a status sink.- Parameters:
sink- status sink to remove
-
getStatusSinks
Get the registered status sinks.- Returns:
- the list of status sinks
-
setCutoffLevel
public static int setCutoffLevel(int cutoffLevel) Set the global cutoff level.- Parameters:
cutoffLevel- new level- Returns:
- the previous level
-
getCutoffLevel
public static int getCutoffLevel()Get the global cutoff level.- Returns:
- the global cutoff level
-
setLevelForNewLoggers
public static int setLevelForNewLoggers(int level) Set the default logging level.- Parameters:
level- the default logging level- Returns:
- the previous default logging level
-
setLevelForNewLoggers
public static int setLevelForNewLoggers(int level, boolean updateExistingLoggers) Set the default logging level for newly created loggers.- Parameters:
level- the default logging levelupdateExistingLoggers- true to update already-created loggers as well- Returns:
- the previous default logging level
-
setGlobalFilter
public static void setGlobalFilter(boolean mute) Enable or disable a global mute filter.- Parameters:
mute- true to mute all regular loggers
-
addGlobalFilter
Add or replace a global filter.- Parameters:
pattern- logger name or package prefix to filter; empty string matches all loggersrequiredLevel- minimum level required for matching loggers
-
removeGlobalFilter
Remove a global filter.- Parameters:
pattern- logger name or package prefix
-
clearGlobalFilters
public static void clearGlobalFilters()Remove all global filters. -
isGloballyDisabled
Deprecated.useisFilteredOut(ILogger, int)instead -
isFilteredOut
Determine whether a message at a given level sent to a logger should be processed or ignored, based onglobal filters.- Parameters:
logger- the loggermessageLevel- the level of the message we want to verify- Returns:
- true if the message should be ignored
-
getEnabledLevel
public static int getEnabledLevel()Get the default logging level.- Returns:
- the default logging level
-
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
Convenience method forgetLogger().status(...).- Parameters:
format- format string if parameters are provided, else standard stringparams- parameters
-
getLogger
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
Create or retrieve a logger attached to and named after a given class.- Parameters:
clazz- class referencelevel- the cut-off level- Returns:
- the logger
-
getLogger
Create or retrieve a named logger.- Parameters:
name- logger namelevel- the cut-off level- Returns:
- the logger
-
getInternalLogger
Create or retrieve an internal logger. INTERNAL USAGE ONLY.- Parameters:
clazz- class reference- Returns:
- the internal logger
-
catching
Log an exception's stack trace.- Parameters:
logger- destination loggert- throwable to log
-
catching
Log an exception's stack trace with an optional message.- Parameters:
logger- destination loggert- throwable to logmessage- optional message prefix
-
catchingDebug
Log an exception's stack trace at debug level.- Parameters:
logger- destination loggert- throwable to log
-
catchingDebug
Log an exception's stack trace at debug level with an optional message.- Parameters:
logger- destination loggert- throwable to logmessage- optional message prefix
-
parseLevel
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 values 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
Convert a log level to a display string.- Parameters:
level- log level- Returns:
- a level name
-
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
-
isFilteredOut(ILogger, int)instead