Package i5.las2peer.logging
Class L2pLogger
java.lang.Object
java.util.logging.Logger
i5.las2peer.logging.L2pLogger
- All Implemented Interfaces:
NodeObserver
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
This is the formatter used for the console output.protected static class
protected static class
This is the formatter used for the log file output. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Level
static final SimpleDateFormat
static final String
static final int
static final int
static final String
static final Level
static final String
static final Level
static final String
Fields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Formatter
This method returns the defaultFormatter
currently used to format log output for console.static Formatter
This method returns the defaultFormatter
currently used to format log output for log files.static L2pLogger
getInstance
(Class<?> cls) This method is used to retrieve a L2pLogger instance.static L2pLogger
getInstance
(String name) This method is used to retrieve a L2pLogger instance.void
log
(MonitoringEvent event) Same as #log(MonitoringEvent, String) without any remarks, just logs the plain event.void
log
(MonitoringEvent event, String remarks) Same as #log(MonitoringEvent, String, String, String) with context main agent as default source agent.void
log
(MonitoringEvent event, String sourceAgentId, String destinationAgentId, String remarks) Same aslog(Long, MonitoringEvent, String, String, String, String, String)
with current system timestamp and no source or destination node.void
log
(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId, String destinationNode, String destinationAgentId, String remarks) Deprecated.void
static void
logEvent
(MonitoringEvent event, Agent actingUser, String message) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)
Writes a log message.static void
logEvent
(MonitoringEvent event, String message) Deprecated.UseContext.monitorEvent(MonitoringEvent, String)
Writes a log message.static void
logEvent
(Node node, Object from, MonitoringEvent event, String message, Agent serviceAgent, Agent actingUser) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)
Writes a log message.static void
logEvent
(Object from, MonitoringEvent event, String message) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String)
Logs a message to the l2p system using the observers.static void
Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)
Writes a log message.protected static void
Appends the stack trace for the givenThrowable
to the givenStringBuilder
.void
Prints a stack trace as nicely ase.printStackTrace()
, but uses the logging system as output.void
setConsoleLevel
(Level level) Sets the log level for the console output of this logger.static void
setGlobalConsoleLevel
(Level level) Same assetConsoleLevel(Level)
for the global static instance.static void
setGlobalLogDirectory
(String directory) Same assetLogDirectory(String)
for the global static instance.static void
setGlobalLogfileLevel
(Level level) Same assetLogfileLevel(Level)
for global static instance.static void
setGlobalLogfilePrefix
(String prefix) Same assetLogfilePrefix(String)
for global static instance.void
setLogDirectory
(String directory) Sets the directory to store log files.void
setLogfileLevel
(Level level) Sets the log level for the log files used in this logger.void
setLogfilePrefix
(String prefix) Sets the prefix used to generate log files.Methods inherited from class java.util.logging.Logger
addHandler, config, config, entering, entering, entering, exiting, exiting, fine, fine, finer, finer, finest, finest, getAnonymousLogger, getAnonymousLogger, getFilter, getGlobal, getHandlers, getLevel, getLogger, getLogger, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers, info, info, isLoggable, log, log, log, log, log, log, logp, logp, logp, logp, logp, logp, logrb, logrb, logrb, logrb, logrb, logrb, logrb, logrb, removeHandler, setFilter, setLevel, setParent, setResourceBundle, setUseParentHandlers, severe, severe, throwing, warning, warning
-
Field Details
-
GLOBAL_NAME
- See Also:
-
DEFAULT_LIMIT_BYTES
public static final int DEFAULT_LIMIT_BYTES- See Also:
-
DEFAULT_LIMIT_FILES
public static final int DEFAULT_LIMIT_FILES- See Also:
-
DEFAULT_ENCODING
- See Also:
-
DEFAULT_LOG_DIRECTORY
- See Also:
-
DEFAULT_LOGFILE_PREFIX
- See Also:
-
DEFAULT_CONSOLE_LEVEL
-
DEFAULT_LOGFILE_LEVEL
-
DEFAULT_OBSERVER_LEVEL
-
DEFAULT_DATE_FORMAT
-
-
Constructor Details
-
L2pLogger
Just calls the parent constructor and adds the new instance to the LogManager.- Parameters:
name
- A name for the logger. This should be a dot-separated name and should normally be based on the package name or class name of the subsystem, such as java.net or javax.swing. It may be null for anonymous Loggers.resourceBundleName
- name of ResourceBundle to be used for localizing messages for this logger. May be null if none of the messages require localization.- Throws:
IllegalArgumentException
- If a logger with the given name is already registered.
-
-
Method Details
-
printStackTrace
Prints a stack trace as nicely ase.printStackTrace()
, but uses the logging system as output.- Parameters:
e
- AThrowable
thats stack trace should be printed.
-
printStackTrace
Appends the stack trace for the givenThrowable
to the givenStringBuilder
.- Parameters:
sb
-StringBuilder
as output for the stack trace.e
- AThrowable
which stack trace should be appended. Ifnull
given, nothing is appended.
-
setGlobalLogDirectory
Same assetLogDirectory(String)
for the global static instance.- Parameters:
directory
- A directory path given as String.null
is equal to "" and the class loader directory.- Throws:
IOException
- If the log file could not be written
-
setLogDirectory
Sets the directory to store log files.- Parameters:
directory
- A directory path given as String.null
is equal to "" and the class loader directory.- Throws:
IOException
- If the log file could not be written
-
setGlobalLogfilePrefix
Same assetLogfilePrefix(String)
for global static instance.- Parameters:
prefix
- Ifnull
is given, file logging will be disabled.- Throws:
IOException
- If the log file could not be written
-
setLogfilePrefix
Sets the prefix used to generate log files.- Parameters:
prefix
- Ifnull
is given, file logging will be disabled.- Throws:
IOException
- If the log file could not be written
-
setGlobalConsoleLevel
Same assetConsoleLevel(Level)
for the global static instance.- Parameters:
level
- The log level to set.
-
setConsoleLevel
Sets the log level for the console output of this logger.- Parameters:
level
- The log level to set.
-
setGlobalLogfileLevel
Same assetLogfileLevel(Level)
for global static instance.- Parameters:
level
- The log level to set.
-
setLogfileLevel
Sets the log level for the log files used in this logger.- Parameters:
level
- The log level to set.
-
log
-
logEvent
Deprecated.UseContext.monitorEvent(MonitoringEvent, String)
Writes a log message. The given event can be used to differentiate between different log messages.- Parameters:
event
- used to differentiate between different log messagesmessage
- A message to log in the monitoring data
-
logEvent
Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)
Writes a log message. The given event can be used to differentiate between different log messages.- Parameters:
event
- used to differentiate between different log messagesactingUser
- can be set to null if unknown / not desiredmessage
- A message to log in the monitoring data
-
logEvent
Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String)
Logs a message to the l2p system using the observers. Since this method will/should only be used in an L2pThread, the message will come from a service or a helper, so a SERVICE_MESSAGE is assumed. Then this message will not be monitored by the monitoring observer.- Parameters:
from
- the calling classevent
- used to differentiate between different log messagesmessage
- A message to log in the monitoring data
-
logEvent
@Deprecated public static void logEvent(Object from, MonitoringEvent event, String message, Agent serviceAgent, Agent actingUser) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)
Writes a log message. The given event can be used to differentiate between different log messages. The serviceAgent and actingUser can be set tonull
if not known. Then this message will not be monitored by the monitoring observer.- Parameters:
from
- the calling classevent
- used to differentiate between different log messagesmessage
- A message to log in the monitoring dataserviceAgent
- can be set to null if unknown / not desiredactingUser
- can be set to null if unknown / not desired
-
logEvent
@Deprecated public static void logEvent(Node node, Object from, MonitoringEvent event, String message, Agent serviceAgent, Agent actingUser) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)
Writes a log message. The given event can be used to differentiate between different log messages. The serviceAgent and actingUser can be set tonull
if not known. Then this message will not be monitored by the monitoring observer.- Parameters:
node
- The node that should be noticed about this eventfrom
- the calling classevent
- used to differentiate between different log messagesmessage
- A message to log in the monitoring dataserviceAgent
- can be set to null if unknown / not desiredactingUser
- can be set to null if unknown / not desired
-
log
Same as #log(MonitoringEvent, String) without any remarks, just logs the plain event.- Parameters:
event
- A monitoring event to log
-
log
Same as #log(MonitoringEvent, String, String, String) with context main agent as default source agent.- Parameters:
event
- A monitoring event to logremarks
- Arbitrary data to log along with the event
-
log
public void log(MonitoringEvent event, String sourceAgentId, String destinationAgentId, String remarks) Same aslog(Long, MonitoringEvent, String, String, String, String, String)
with current system timestamp and no source or destination node.- Parameters:
event
- A monitoring event to logsourceAgentId
- A source agent id for this monitoring eventdestinationAgentId
- A destination agent id for this monitoring eventremarks
- Arbitrary data to log along with the event
-
log
@Deprecated public void log(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId, String destinationNode, String destinationAgentId, String remarks) Deprecated.Uselog(Long, MonitoringEvent, String, String, String, String, String)
instead. The coupling between nodes and services is softened now.Description copied from interface:NodeObserver
Each call represents one event to log by this observer. All parameters except the time stamp and the event may be null.- Specified by:
log
in interfaceNodeObserver
- Parameters:
timestamp
- UNIX time stamp of the eventevent
- the event to logsourceNode
- a source (p2p) node of the event (e.g. message sender)sourceAgentId
- a source (las2peer) agent of the event (e.g. message sender)destinationNode
- a destination (p2p) node for the event (e.g. message receiver)destinationAgentId
- a destination (las2peer) agent of the event (e.g. message receiver)remarks
- (optional) additional remarks
-
getGlobalConsoleFormatter
This method returns the defaultFormatter
currently used to format log output for console.- Returns:
- Returns the console formatter.
-
getGlobalLogfileFormatter
This method returns the defaultFormatter
currently used to format log output for log files.- Returns:
- Returns the log file formatter.
-
getInstance
This method is used to retrieve a L2pLogger instance.- Parameters:
cls
- Should be the class this instance is used with.- Returns:
- Returns a L2pLogger instance for the given class.
- Throws:
ClassCastException
- If someone overloaded the loggers instance by adding some other logger implementation with the same name. In this case you may use Java native method by callingLogger.getLogger(String)
.
-
getInstance
This method is used to retrieve a L2pLogger instance.- Parameters:
name
- A name for the new logger instance. Should be the name of your current class by default. Like L2pLogger.class.getCanonicalName()- Returns:
- Returns a L2pLogger instance for the given name.
- Throws:
ClassCastException
- If someone overloaded the loggers instance by adding some other logger implementation with the same name. In this case you may use Java native method by callingLogger.getLogger(String)
.
-
log(Long, MonitoringEvent, String, String, String, String, String)
instead.