Interface SilverLogger
- All Known Implementing Classes:
SysLogger
This custom logger is an adapter to a concrete underlying logging backend to use to log messages. The logging backend can be the logging subsystem of the used application server or a tiers logging framework. With the adapter it can then be easy to switch from an implementation to the other without impacting the logging use in the code of Silverpeas.
Each logger is identified by a namespace and belongs to an hierarchical tree of loggers rooted to
the
silverpeas namespace. The namespace of a logger defines the position of the logger
in the tree: a
logger with as namespace silverpeas.kernel is a child of the root Silverpeas logger.
When a logger of a given namespace isn't found, then it is the configuration of the nearest
defined parent logger that is used (logging level and handler). In Silverpeas, the handlers (aka
the snippet of codes that handles the messages into logs) are predefined by configuration and
cannot be modified programmatically.
The convention mapping between the namespace of a logger and the package name of an object that
logs messages is that all packages rooted to the package org.silverpeas are mapped,
each of them, to a namespace of identical name rooted to the Silverpeas root namespace
silverpeas. For others packages, the namespace is the package fully qualified name.
An implementation of this interface must be a wrapper of a concrete logging mechanism and
instances of the implementation must be manufactured by the
SilverLoggerFactory factory.
- Author:
- mmoquillon
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidLogs a debugging message with the specified parameters.default voidLogs an debugging message with the specified parameters.default voidLogs an error message with the specified parameters.default voidLogs an error message with the specified parameters.default voidLogs an error message with the specified parameters.default voidLogs an error message with the specified parameters.getLevel()Gets the log Level of this Logger.static SilverLoggerGets a logger for the specified object.static SilverLoggerGets the logger that is defined for the specified logging namespace.Gets the namespace of this logger.default voidLogs an information message with the specified parameters.booleanisLoggable(Level level) Checks if a message of the given level would actually be logged by this logger.voidLogs a message at the specified level, with the specified parameters if any.voidLogs a message at the specified level, with the specified parameters if any and with a Throwable object if any.voidSets the log level specifying which message levels will be logged by this logger.default SilverLoggerLogs silently the specified error.default voidLogs a warning message with the specified parameters.default voidLogs a warning message with the specified parameters.
-
Method Details
-
getLogger
Gets the logger that is defined for the specified logging namespace. The logger getting is delegated to aSilverLoggerProviderinstance.- Parameters:
module- a logging namespace. It is the name or a category under which the messages will be log.- Returns:
- a logger instance provided by a
SilverLoggerProviderinstance. - See Also:
-
getLogger
Gets a logger for the specified object. The logger getting is delegated to aSilverLoggerProviderinstance.- Parameters:
object- the object from which the logging namespace is determined. The logging namespace is found from the package name of the object. In Silverpeas, each logger namespace matches a package name, starting from the *silverpeassubpackage: for a packageorg.silverpeas.core.io, there is a logger with the namespacesilverpeas.core.io.- Returns:
- a logger instance provided by a
SilverLoggerProviderinstance. - See Also:
-
getNamespace
String getNamespace()Gets the namespace of this logger. Each logger is defined by a unique dot separated namespace.- Returns:
- the namespace of this logger.
-
getLevel
Level getLevel()Gets the log Level of this Logger. If no level was explicitly set for his logger, its effective level is then inherited from its parent.- Returns:
- the level of this logger.
-
setLevel
Sets the log level specifying which message levels will be logged by this logger. Message levels lower than this value will be discarded. If the new level is null, it means that this node should inherit its level from its nearest ancestor with a specific (non-null) level value.- Parameters:
level- the new value for the log level (may be null).
-
isLoggable
Checks if a message of the given level would actually be logged by this logger. This check is based on the Loggers effective level, which may be inherited from its parent.- Parameters:
level- a logging level.- Returns:
- true if a message of the given level would actually be logged. False otherwise.
-
log
Logs a message at the specified level, with the specified parameters if any and with a Throwable object if any. If the logger is currently enabled for the given message level then a corresponding logging record is created and forwarded to all the registered output handlers objects.- Parameters:
level- the level of the message to log.message- the message to log.parameters- zero, one or more parameters to the message. Shouldn't be null.error- an error to log with the message.
-
log
Logs a message at the specified level, with the specified parameters if any.- Parameters:
level- the level of the message to log.message- the message to log.parameters- zero, one or more parameters to the message.
-
error
Logs an error message with the specified parameters.- Parameters:
message- the message to log.parameters- zero, one or more parameters to set to the message
-
error
Logs an error message with the specified parameters.- Parameters:
error- the cause of the error.
-
error
Logs an error message with the specified parameters.- Parameters:
message- the message to log.error- the cause of the error.
-
error
Logs an error message with the specified parameters.- Parameters:
message- the message to log.parameters- zero, one or more parameters to set to the messageerror- the cause of the error.
-
warn
Logs a warning message with the specified parameters.- Parameters:
message- the message to log.parameters- zero, one or more parameters to set to the message
-
warn
Logs a warning message with the specified parameters.Only the message of the error will be logged.
- Parameters:
error- the cause of the error.
-
info
Logs an information message with the specified parameters.- Parameters:
message- the message to log.parameters- zero, one or more parameters to set to the message
-
debug
Logs a debugging message with the specified parameters.- Parameters:
message- the message to log.parameters- zero, one or more parameters to set to the message
-
debug
Logs an debugging message with the specified parameters. The message is computed by a function that will be invoked only if the actual logger level is higher or equal than the message level.Usually, debugging message are computed by executing codes that shouldn't be ran in a nominal execution context. In order to avoid this code to be executed when the logger level is lower than the debug level, it can be written within a function whose the invocation is left to the logger responsibility.
- Parameters:
messageSupplier- a function that will computed the message to log.
-
silent
Logs silently the specified error. The message is actually wiped out. This method is mainly dedicated to explicitly indicate the error is expected in some well-defined circumstances; it is a computation branch in the nominal execution flow.Be caution by using this method; it is more efficient to use the if-else condition than the try-catch instruction to perform a default treatment on error cases. This method is to be used when a method marked as throwing an exception is invoked and for which the exception is, in the context of the invocation, can be expected.
- Parameters:
error- the error to wipe out.- Returns:
- the logger itself.
-