Package i5.las2peer.logging
Class L2pLogger
java.lang.Object
java.util.logging.Logger
i5.las2peer.logging.L2pLogger
- All Implemented Interfaces:
NodeObserver
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThis is the formatter used for the console output.protected static classprotected static classThis is the formatter used for the log file output. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Levelstatic final SimpleDateFormatstatic final Stringstatic final intstatic final intstatic final Stringstatic final Levelstatic final Stringstatic final Levelstatic final StringFields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FormatterThis method returns the defaultFormattercurrently used to format log output for console.static FormatterThis method returns the defaultFormattercurrently used to format log output for log files.static L2pLoggergetInstance(Class<?> cls) This method is used to retrieve a L2pLogger instance.static L2pLoggergetInstance(String name) This method is used to retrieve a L2pLogger instance.voidlog(MonitoringEvent event) Same as #log(MonitoringEvent, String) without any remarks, just logs the plain event.voidlog(MonitoringEvent event, String remarks) Same as #log(MonitoringEvent, String, String, String) with context main agent as default source agent.voidlog(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.voidlog(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId, String destinationNode, String destinationAgentId, String remarks) Deprecated.voidstatic voidlogEvent(MonitoringEvent event, Agent actingUser, String message) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)Writes a log message.static voidlogEvent(MonitoringEvent event, String message) Deprecated.UseContext.monitorEvent(MonitoringEvent, String)Writes a log message.static voidlogEvent(Node node, Object from, MonitoringEvent event, String message, Agent serviceAgent, Agent actingUser) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)Writes a log message.static voidlogEvent(Object from, MonitoringEvent event, String message) Deprecated.UseContext.monitorEvent(Object, MonitoringEvent, String)Logs a message to the l2p system using the observers.static voidDeprecated.UseContext.monitorEvent(Object, MonitoringEvent, String, boolean)Writes a log message.protected static voidAppends the stack trace for the givenThrowableto the givenStringBuilder.voidPrints a stack trace as nicely ase.printStackTrace(), but uses the logging system as output.voidsetConsoleLevel(Level level) Sets the log level for the console output of this logger.static voidsetGlobalConsoleLevel(Level level) Same assetConsoleLevel(Level)for the global static instance.static voidsetGlobalLogDirectory(String directory) Same assetLogDirectory(String)for the global static instance.static voidsetGlobalLogfileLevel(Level level) Same assetLogfileLevel(Level)for global static instance.static voidsetGlobalLogfilePrefix(String prefix) Same assetLogfilePrefix(String)for global static instance.voidsetLogDirectory(String directory) Sets the directory to store log files.voidsetLogfileLevel(Level level) Sets the log level for the log files used in this logger.voidsetLogfilePrefix(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- AThrowablethats stack trace should be printed.
-
printStackTrace
Appends the stack trace for the givenThrowableto the givenStringBuilder.- Parameters:
sb-StringBuilderas output for the stack trace.e- AThrowablewhich stack trace should be appended. Ifnullgiven, nothing is appended.
-
setGlobalLogDirectory
Same assetLogDirectory(String)for the global static instance.- Parameters:
directory- A directory path given as String.nullis 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.nullis 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- Ifnullis 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- Ifnullis 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 tonullif 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 tonullif 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:NodeObserverEach call represents one event to log by this observer. All parameters except the time stamp and the event may be null.- Specified by:
login 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 defaultFormattercurrently used to format log output for console.- Returns:
- Returns the console formatter.
-
getGlobalLogfileFormatter
This method returns the defaultFormattercurrently 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.