java.lang.Object
org.snmp4j.log.LogFactory
- Direct Known Subclasses:
ConsoleLogFactory
,JavaLogFactory
The
LogFactory
singleton is used by SNMP4J to determine
the logging framework used to process SNMP4J log messages. By default
NoLogger
instances are used.- Since:
- 1.2.1
- Version:
- 3.4.1
- Author:
- Frank Fock
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addHandler
(LogAdapter logAdapter, String handlerName, Map<String, String> handlerConfig) protected LogAdapter
createLogger
(Class<?> c) Creates a Logger for the specified class.protected LogAdapter
createLogger
(String className) Creates a Logger for the specified class.static LogFactory
Gets the log factory to be used by SNMP4J.static LogAdapter
Gets the logger for the supplied class.static LogAdapter
Gets the logger for the supplied class name.Returns the top level logger.loggers()
Returns all available LogAdapters in depth first order.protected void
removeAllHandlers
(LogAdapter logAdapter) void
reset()
Reset the logging configuration.void
resetLogger
(LogAdapter logger) Close all handlers of a logger and set its level tonull
if it is not the root logger.static void
setLogFactory
(LogFactory factory) Sets the log factory to be used by SNMP4J.void
setLoggerConfigPrefix
(String loggerConfigPrefix) Set the properties name prefix, including the trailing ".", used byupdateConfiguration(Properties)
andwriteConfiguration(Properties)
for logger properties.void
setLogHandlerConfigPrefix
(String logHandlerConfigPrefix) Set the properties name prefix, including the trailing ".", used byupdateConfiguration(Properties)
andwriteConfiguration(Properties)
for log handler properties.void
updateConfiguration
(Properties config) Configure the log levels of theLogAdapter
specified in theProperties
provided by thepropertiesReader
parameter.protected void
updateLogger
(LogAdapter logAdapter, Map<String, String> loggerConfig) void
writeConfiguration
(Properties config) protected void
writeConfiguration
(Properties config, LogAdapter logAdapter) protected String
writeConfiguration
(Properties config, LogAdapter logAdapter, Object handler)
-
Field Details
-
SNMP4J_LOG_FACTORY_SYSTEM_PROPERTY
- See Also:
-
SNMP4J_LOG_FACTORY_LOGGER_DEFAULT_PREFIX
- See Also:
-
SNMP4J_LOG_FACTORY_LOG_HANDLER_DEFAULT_PREFIX
- See Also:
-
SNMP4J_LOG_ID
- See Also:
-
SNMP4J_LOG_LEVEL
- See Also:
-
SNMP4J_LOG_HANDLER
- See Also:
-
SNMP4J_LOG_HANDLER_LIST
- See Also:
-
-
Constructor Details
-
LogFactory
public LogFactory()
-
-
Method Details
-
getLogger
Gets the logger for the supplied class.- Parameters:
c
- the class for which a logger needs to be created.- Returns:
- the
LogAdapter
instance.
-
getRootLogger
Returns the top level logger.- Returns:
- a LogAdapter instance.
- Since:
- 1.7
-
getLogger
Gets the logger for the supplied class name.- Parameters:
className
- the class name for which a logger needs to be created.- Returns:
- the
LogAdapter
instance. - Since:
- 1.7
-
createLogger
Creates a Logger for the specified class. This method returns theNoLogger
logger instance which disables logging. Overwrite this method the return a custom logger to enable logging for SNMP4J.- Parameters:
c
- the class for which a logger needs to be created.- Returns:
- the
LogAdapter
instance.
-
createLogger
Creates a Logger for the specified class. This method returns theNoLogger
logger instance which disables logging. Overwrite this method the return a custom logger to enable logging for SNMP4J.- Parameters:
className
- the class name for which a logger needs to be created.- Returns:
- the
LogAdapter
instance. - Since:
- 1.7
-
setLogFactory
Sets the log factory to be used by SNMP4J. Call this method before any other SNMP4J class is referenced or created to set and use a custom log factory.- Parameters:
factory
- aLogFactory
instance.
-
getLogFactory
Gets the log factory to be used by SNMP4J. If the log factory has not been initialized bysetLogFactory(org.snmp4j.log.LogFactory)
a new instance ofLogFactory
is returned.- Returns:
- a
LogFactory
instance. - Since:
- 1.7
-
loggers
Returns all available LogAdapters in depth first order.- Returns:
- a read-only Iterator.
- Since:
- 1.7
-
resetLogger
Close all handlers of a logger and set its level tonull
if it is not the root logger.- Parameters:
logger
- the logger to be reset.- Since:
- 3.4.1
-
getLoggerConfigPrefix
-
setLoggerConfigPrefix
Set the properties name prefix, including the trailing ".", used byupdateConfiguration(Properties)
andwriteConfiguration(Properties)
for logger properties.- Parameters:
loggerConfigPrefix
- the prefix forLogAdapter
configuration properties.- Since:
- 3.4.1
-
getLogHandlerConfigPrefix
-
setLogHandlerConfigPrefix
Set the properties name prefix, including the trailing ".", used byupdateConfiguration(Properties)
andwriteConfiguration(Properties)
for log handler properties.- Parameters:
logHandlerConfigPrefix
- the prefix for log handler configuration properties.- Since:
- 3.4.1
-
reset
public void reset()Reset the logging configuration. For all named log adapters, the reset operation removes and closes all handlers (log factory specific) and (except for the root logger) sets the level tonull
. The root logger's level is set toLogLevel.INFO
.- Since:
- 3.4.1
-
updateConfiguration
Configure the log levels of theLogAdapter
specified in theProperties
provided by thepropertiesReader
parameter. For example:snmp4j.log.level.<loggerName>=<LogLevel>
- Parameters:
config
- theProperties
that contain properties with the prefixesgetLoggerConfigPrefix()
andgetLogHandlerConfigPrefix()
.
-
removeAllHandlers
-
addHandler
protected void addHandler(LogAdapter logAdapter, String handlerName, Map<String, String> handlerConfig) -
updateLogger
-
writeConfiguration
-
writeConfiguration
-
writeConfiguration
-