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 int
static final int
static final int
Special level used to log exception related data such as stack traces.static final int
static final int
static final int
static final int
static final int
Reserved for internal usestatic final int
special log level indicating a status message; logs with that status will not be directed to the regular sinksstatic final int
static final int
static boolean
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferSink
addDestinationBuffer
(List<CharSequence> buffer) Add a destination buffer to the list of log message recipients.static StreamSink
Add a destination stream to the list of log message recipients.static void
addGlobalFilter
(String pattern, int requiredLevel) static void
addStatusSink
(LogStatusSink sink) Register a status sink.static void
static void
static void
catchingDebug
(ILogger logger, Throwable t) static void
catchingDebug
(ILogger logger, Throwable t, String message) static void
static int
static List<BufferSink>
Get the list of registered buffer sinks.static List<StreamSink>
Get the list of registered stream sinks.static int
Get the default logging level.static ILogger
getInternalLogger
(Class<?> clazz) Create or retrieve an internal logger.static int
getLevelFromPrefixLetter
(char ch) Retrieve the log level associated to the provided prefix letter.static ILogger
Create or retrieve the anonymous logger.static ILogger
Create or retrieve a logger attached to and named after a given class.static ILogger
Create or retrieve a logger attached to and named after a given class.static ILogger
Create or retrieve a named logger.static char
getPrefixLetterForLevel
(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 boolean
isGloballyDisabled
(ILogger logger) static String
levelToString
(int level) static int
parseLevel
(String s) Parse a log level name (or number) to a log level integer usable by Logger objects.static BufferSink
removeDestinationBuffer
(List<CharSequence> buffer) Remove a destination buffer.static StreamSink
Remove a destination stream.static void
removeGlobalFilter
(String pattern) static void
Unregister a status sink.static int
setCutoffLevel
(int cutoffLevel) static void
setGlobalFilter
(boolean mute) static int
setLevelForNewLoggers
(int level) Set the default logging levelstatic int
setLevelForNewLoggers
(int level, boolean updateExistingLoggers) static void
Convenience 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
-