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.loggingg.GlobalLog;
class Xyz {
private static final ILogger logger = GlobalLog.getLogger(Xyz.class);
...
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intSpecial level used to log exception related data such as stack traces.static final intstatic final intstatic final intstatic final intstatic final intReserved for internal usestatic final intspecial log level indicating a status message; logs with that status will not be directed to the regular sinksstatic final intstatic final intstatic booleanstatic final int -
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) static voidaddStatusSink(LogStatusSink sink) Register a status sink.static voidstatic voidstatic voidcatchingDebug(ILogger logger, Throwable t) static voidcatchingDebug(ILogger logger, Throwable t, String message) static voidstatic intstatic 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>static booleanisGloballyDisabled(ILogger logger) static StringlevelToString(int level) 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) static voidUnregister a status sink.static intsetCutoffLevel(int cutoffLevel) static voidsetGlobalFilter(boolean mute) static intsetLevelForNewLoggers(int level) Set the default logging levelstatic intsetLevelForNewLoggers(int level, boolean updateExistingLoggers) static voidConvenience method forgetLogger().status(...).
-
Field Details
-
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_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_LEVEL -
prefixWithLevel
public static boolean prefixWithLevel
-
-
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:
-
addStatusSink
Register a status sink. Those sinks receive only logs having the special levelLEVEL_STATUS.- Parameters:
sink-
-
removeStatusSink
Unregister a status sink.- Parameters:
sink-
-
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
-
removeGlobalFilter
-
clearGlobalFilters
public static void clearGlobalFilters() -
isGloballyDisabled
-
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-params-
-
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-- Returns:
-
catching
-
catching
-
catchingDebug
-
catchingDebug
-
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 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
-
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
-