- java.lang.Object
-
- org.snmp4j.log.LogFactory
-
- Direct Known Subclasses:
ConsoleLogFactory,JavaLogFactory
public class LogFactory extends java.lang.ObjectTheLogFactorysingleton is used by SNMP4J to determine the logging framework used to process SNMP4J log messages. By defaultNoLoggerinstances are used.- Since:
- 1.2.1
- Version:
- 3.4.1
- Author:
- Frank Fock
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSNMP4J_LOG_FACTORY_LOG_HANDLER_DEFAULT_PREFIXstatic java.lang.StringSNMP4J_LOG_FACTORY_LOGGER_DEFAULT_PREFIXstatic java.lang.StringSNMP4J_LOG_FACTORY_SYSTEM_PROPERTYstatic java.lang.StringSNMP4J_LOG_HANDLERstatic java.lang.StringSNMP4J_LOG_HANDLER_LISTstatic java.lang.StringSNMP4J_LOG_IDstatic java.lang.StringSNMP4J_LOG_LEVEL
-
Constructor Summary
Constructors Constructor Description LogFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddHandler(LogAdapter logAdapter, java.lang.String handlerName, java.util.Map<java.lang.String,java.lang.String> handlerConfig)protected LogAdaptercreateLogger(java.lang.Class<?> c)Creates a Logger for the specified class.protected LogAdaptercreateLogger(java.lang.String className)Creates a Logger for the specified class.static LogFactorygetLogFactory()Gets the log factory to be used by SNMP4J.static LogAdaptergetLogger(java.lang.Class<?> c)Gets the logger for the supplied class.static LogAdaptergetLogger(java.lang.String className)Gets the logger for the supplied class name.java.lang.StringgetLoggerConfigPrefix()java.lang.StringgetLogHandlerConfigPrefix()LogAdaptergetRootLogger()Returns the top level logger.java.util.Iterator<LogAdapter>loggers()Returns all available LogAdapters in depth first order.protected voidremoveAllHandlers(LogAdapter logAdapter)voidreset()Reset the logging configuration.voidresetLogger(LogAdapter logger)Close all handlers of a logger and set its level tonullif it is not the root logger.static voidsetLogFactory(LogFactory factory)Sets the log factory to be used by SNMP4J.voidsetLoggerConfigPrefix(java.lang.String loggerConfigPrefix)Set the properties name prefix, including the trailing ".", used byupdateConfiguration(Properties)andwriteConfiguration(Properties)for logger properties.voidsetLogHandlerConfigPrefix(java.lang.String logHandlerConfigPrefix)Set the properties name prefix, including the trailing ".", used byupdateConfiguration(Properties)andwriteConfiguration(Properties)for log handler properties.voidupdateConfiguration(java.util.Properties config)Configure the log levels of theLogAdapterspecified in thePropertiesprovided by thepropertiesReaderparameter.protected voidupdateLogger(LogAdapter logAdapter, java.util.Map<java.lang.String,java.lang.String> loggerConfig)voidwriteConfiguration(java.util.Properties config)protected voidwriteConfiguration(java.util.Properties config, LogAdapter logAdapter)protected java.lang.StringwriteConfiguration(java.util.Properties config, LogAdapter logAdapter, java.lang.Object handler)
-
-
-
Field Detail
-
SNMP4J_LOG_FACTORY_SYSTEM_PROPERTY
public static final java.lang.String SNMP4J_LOG_FACTORY_SYSTEM_PROPERTY
- See Also:
- Constant Field Values
-
SNMP4J_LOG_FACTORY_LOGGER_DEFAULT_PREFIX
public static final java.lang.String SNMP4J_LOG_FACTORY_LOGGER_DEFAULT_PREFIX
- See Also:
- Constant Field Values
-
SNMP4J_LOG_FACTORY_LOG_HANDLER_DEFAULT_PREFIX
public static final java.lang.String SNMP4J_LOG_FACTORY_LOG_HANDLER_DEFAULT_PREFIX
- See Also:
- Constant Field Values
-
SNMP4J_LOG_ID
public static final java.lang.String SNMP4J_LOG_ID
- See Also:
- Constant Field Values
-
SNMP4J_LOG_LEVEL
public static final java.lang.String SNMP4J_LOG_LEVEL
- See Also:
- Constant Field Values
-
SNMP4J_LOG_HANDLER
public static final java.lang.String SNMP4J_LOG_HANDLER
- See Also:
- Constant Field Values
-
SNMP4J_LOG_HANDLER_LIST
public static final java.lang.String SNMP4J_LOG_HANDLER_LIST
- See Also:
- Constant Field Values
-
-
Method Detail
-
getLogger
public static LogAdapter getLogger(java.lang.Class<?> c)
Gets the logger for the supplied class.- Parameters:
c- the class for which a logger needs to be created.- Returns:
- the
LogAdapterinstance.
-
getRootLogger
public LogAdapter getRootLogger()
Returns the top level logger.- Returns:
- a LogAdapter instance.
- Since:
- 1.7
-
getLogger
public static LogAdapter getLogger(java.lang.String className)
Gets the logger for the supplied class name.- Parameters:
className- the class name for which a logger needs to be created.- Returns:
- the
LogAdapterinstance. - Since:
- 1.7
-
createLogger
protected LogAdapter createLogger(java.lang.Class<?> c)
Creates a Logger for the specified class. This method returns theNoLoggerlogger 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
LogAdapterinstance.
-
createLogger
protected LogAdapter createLogger(java.lang.String className)
Creates a Logger for the specified class. This method returns theNoLoggerlogger 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
LogAdapterinstance. - Since:
- 1.7
-
setLogFactory
public static void setLogFactory(LogFactory factory)
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- aLogFactoryinstance.
-
getLogFactory
public static LogFactory 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 ofLogFactoryis returned.- Returns:
- a
LogFactoryinstance. - Since:
- 1.7
-
loggers
public java.util.Iterator<LogAdapter> loggers()
Returns all available LogAdapters in depth first order.- Returns:
- a read-only Iterator.
- Since:
- 1.7
-
resetLogger
public void resetLogger(LogAdapter logger)
Close all handlers of a logger and set its level tonullif it is not the root logger.- Parameters:
logger- the logger to be reset.- Since:
- 3.4.1
-
getLoggerConfigPrefix
public java.lang.String getLoggerConfigPrefix()
-
setLoggerConfigPrefix
public void setLoggerConfigPrefix(java.lang.String loggerConfigPrefix)
Set the properties name prefix, including the trailing ".", used byupdateConfiguration(Properties)andwriteConfiguration(Properties)for logger properties.- Parameters:
loggerConfigPrefix- the prefix forLogAdapterconfiguration properties.- Since:
- 3.4.1
-
getLogHandlerConfigPrefix
public java.lang.String getLogHandlerConfigPrefix()
-
setLogHandlerConfigPrefix
public void setLogHandlerConfigPrefix(java.lang.String logHandlerConfigPrefix)
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
public void updateConfiguration(java.util.Properties config)
Configure the log levels of theLogAdapterspecified in thePropertiesprovided by thepropertiesReaderparameter. For example:snmp4j.log.level.<loggerName>=<LogLevel>- Parameters:
config- thePropertiesthat contain properties with the prefixesgetLoggerConfigPrefix()andgetLogHandlerConfigPrefix().
-
removeAllHandlers
protected void removeAllHandlers(LogAdapter logAdapter)
-
addHandler
protected void addHandler(LogAdapter logAdapter, java.lang.String handlerName, java.util.Map<java.lang.String,java.lang.String> handlerConfig)
-
updateLogger
protected void updateLogger(LogAdapter logAdapter, java.util.Map<java.lang.String,java.lang.String> loggerConfig)
-
writeConfiguration
public void writeConfiguration(java.util.Properties config)
-
writeConfiguration
protected void writeConfiguration(java.util.Properties config, LogAdapter logAdapter)
-
writeConfiguration
protected java.lang.String writeConfiguration(java.util.Properties config, LogAdapter logAdapter, java.lang.Object handler)
-
-