alma::acs::logging::config::LogConfig Class Reference

Collaboration diagram for alma::acs::logging::config::LogConfig:
Collaboration graph
[legend]

List of all members.

Classes

class  LockableUnnamedLogger

Public Member Functions

 LogConfig ()
void setCDB (DALOperations cdb)
void setCDBLoggingConfigPath (String path)
void setCDBComponentPath (String compLoggerName, String path)
void initialize (boolean cdbBeatsProperties) throws LogConfigException
String getCentralizedLogger ()
int getDispatchPacketSize ()
AcsLogLevelDefinition getImmediateDispatchLevel ()
int getFlushPeriodSeconds ()
int getMaxLogQueueSize ()
AcsLogLevelDefinition getDefaultMinLogLevelLocal ()
void setDefaultMinLogLevelLocal (AcsLogLevelDefinition newLevel)
AcsLogLevelDefinition getDefaultMinLogLevel ()
void setDefaultMinLogLevel (AcsLogLevelDefinition newLevel)
Set< String > getLoggerNames ()
boolean isKnownLogger (String loggerName)
boolean hasCustomConfig (String loggerName)
LockableUnnamedLogger getNamedLoggerConfig (String loggerName)
void setNamedLoggerConfig (String loggerName, LockableUnnamedLogger config) throws AcsJIllegalArgumentEx
void setNamedLoggerConfig (String loggerName, UnnamedLogger config) throws AcsJIllegalArgumentEx
void clearNamedLoggerConfig (String loggerName)
void setMinLogLevelLocal (AcsLogLevelDefinition newLevel, String loggerName)
void setMinLogLevel (AcsLogLevelDefinition newLevel, String loggerName)
void setAndLockMinLogLevel (AcsLogLevelDefinition newLevel, String loggerName)
boolean renameNamedLoggerConfig (String oldLoggerName, String newLoggerName)
void addSubscriber (LogConfigSubscriber subscriber)
void removeSubscriber (LogConfigSubscriber subscriber)
void setInternalLogger (Logger logger)

Static Public Attributes

static final String PROPERTYNAME_MIN_LOG_LEVEL_LOCAL = "ACS.logstdout"
static final String PROPERTYNAME_MIN_LOG_LEVEL = "ACS.log.minlevel.remote"
static final String PROPERTYNAME_NAMED_LOGGER_LEVELS = "ACS.log.minlevel.namedloggers"

Protected Member Functions

void log (Level level, String msg, Throwable thr)

Package Functions

String getLogConfigXml (String cdbPathParent, String xpathLogConfigNode) throws CDBXMLErrorEx, CDBRecordDoesNotExistEx, ParserConfigurationException, SAXException, IOException, XPathExpressionException, TransformerException
void notifySubscribers ()

Static Package Attributes

static final String CDBNAME_LoggingConfig = LoggingConfig.class.getSimpleName()
static final String CDBNAME_ComponentLogger = "ComponentLogger"

Private Member Functions

void configureDefaultLevelsFromProperties ()
void configureNamedLoggerLevelsFromProperties ()
AcsLogLevelDefinition convertLegalLogLevel (LogLevel legalLogLevel)
void storeNamedLoggerConfig (String loggerName, LockableUnnamedLogger config)

Private Attributes

Logger logger
DALOperations cdb
String cdbLoggingConfigPath
Map< String, String > cdbComponentPaths
LoggingConfig loggingConfig
final Map< String,
LockableUnnamedLogger
namedLoggerConfigs
final List< LogConfigSubscribersubscriberList

Detailed Description

Class that encapsulates all configuration sources (defaults, properties, CDB) for Java logging, and supports runtime updates of logging configuration based on these sources. This class can be used by a process such as the Java container or the manager, in order to configure all its loggers (e.g. container logger, component loggers, ORB logger).

Author:
hsommer

Constructor & Destructor Documentation

alma::acs::logging::config::LogConfig::LogConfig (  )  [inline]

Member Function Documentation

void alma::acs::logging::config::LogConfig::addSubscriber ( LogConfigSubscriber  subscriber  )  [inline]
void alma::acs::logging::config::LogConfig::clearNamedLoggerConfig ( String  loggerName  )  [inline]

Clears log level settings for the given named logger, so that it uses default log levels. Notifies all listeners. Ignores this call if loggerName is null.

References notifySubscribers(), and storeNamedLoggerConfig().

Referenced by com::cosylab::acs::maci::plug::ManagerProxyImpl::set_logLevels(), and alma::acs::logging::config::LogConfigTest::testLockingRemoteLevel().

void alma::acs::logging::config::LogConfig::configureDefaultLevelsFromProperties (  )  [inline, private]

Reads the properties ACS.logstdout (name defined as PROPERTYNAME_MIN_LOG_LEVEL) and ACS.log.minlevel.remote (name defined as PROPERTYNAME_MIN_LOG_LEVEL_LOCAL) and, if the property is defined, sets the respective default level. Prior values are lost.

References log(), loggingConfig, PROPERTYNAME_MIN_LOG_LEVEL, and PROPERTYNAME_MIN_LOG_LEVEL_LOCAL.

Referenced by initialize(), and LogConfig().

void alma::acs::logging::config::LogConfig::configureNamedLoggerLevelsFromProperties (  )  [inline, private]

Reads the property ACS.log.minlevel.namedloggers (name defined as PROPERTYNAME_NAMED_LOGGER_LEVELS) and, if the property is defined, sets the respective named logger levels. Prior values are lost.

References log(), PROPERTYNAME_NAMED_LOGGER_LEVELS, and storeNamedLoggerConfig().

Referenced by initialize().

AcsLogLevelDefinition alma::acs::logging::config::LogConfig::convertLegalLogLevel ( LogLevel  legalLogLevel  )  [inline, private]

Helper method that converts an integer log level to the matching enum literal. It suppresses the AcsJIllegalArgumentEx because the level must have been validated during the config init (and we wouldn't be bothered about exceptions here if we had stored the converted enum literal instead of the castor class). Therefore a lame log and runtime ex are thrown just in case, but no AcsJIllegalArgumentEx gets thrown on.

References log().

Referenced by getDefaultMinLogLevel(), getDefaultMinLogLevelLocal(), and getImmediateDispatchLevel().

String alma::acs::logging::config::LogConfig::getCentralizedLogger (  )  [inline]
AcsLogLevelDefinition alma::acs::logging::config::LogConfig::getDefaultMinLogLevel (  )  [inline]
AcsLogLevelDefinition alma::acs::logging::config::LogConfig::getDefaultMinLogLevelLocal (  )  [inline]
int alma::acs::logging::config::LogConfig::getDispatchPacketSize (  )  [inline]
int alma::acs::logging::config::LogConfig::getFlushPeriodSeconds (  )  [inline]
AcsLogLevelDefinition alma::acs::logging::config::LogConfig::getImmediateDispatchLevel (  )  [inline]
String alma::acs::logging::config::LogConfig::getLogConfigXml ( String  cdbPathParent,
String  xpathLogConfigNode 
) throws CDBXMLErrorEx, CDBRecordDoesNotExistEx, ParserConfigurationException, SAXException, IOException, XPathExpressionException, TransformerException [inline, package]

Reads the CDB element from the given path as XML, and extracts the child element that must be uniquely identified by the XPath expression in xpathLogConfigNode.

TODO: move the Node-to-XML-String code to a general utility package and return just the Node -- any client can then easily turn it into a String if needed. For Castor-parsing, a node is fine, see Unmarshaller#unmarshal(Node).

Parameters:
cdbPathParent path to container, manager, or component config node
xpathExpression For example, for containers and managers //LoggingConfig, for multiple-components-xml //_[='myCompName']/ComponentLogger
Returns:
XML String for the requested child, or null if no unique xml child element was found.
Exceptions:
CDBRecordDoesNotExistEx 
CDBXMLErrorEx 
ParserConfigurationException 
IOException 
SAXException 
XPathExpressionException 
TransformerException 
IllegalStateException if the cdb ref has not been set

References cdb, and com::cosylab::CDB::DALOperations::get_DAO().

Referenced by initialize(), and alma::acs::logging::config::LogConfigTest::testGetLogConfigXml().

Set<String> alma::acs::logging::config::LogConfig::getLoggerNames (  )  [inline]
int alma::acs::logging::config::LogConfig::getMaxLogQueueSize (  )  [inline]
LockableUnnamedLogger alma::acs::logging::config::LogConfig::getNamedLoggerConfig ( String  loggerName  )  [inline]
boolean alma::acs::logging::config::LogConfig::hasCustomConfig ( String  loggerName  )  [inline]

Checks if there is a level configuration for this particular logger.

Parameters:
loggerName 
Returns:
false if the logger is not known or uses the default configuration

References namedLoggerConfigs.

Referenced by com::cosylab::acs::maci::plug::ManagerProxyImpl::get_logLevels(), and alma::acs::logging::ClientLogManager::getLoggerForCorba().

void alma::acs::logging::config::LogConfig::initialize ( boolean  cdbBeatsProperties  )  throws LogConfigException [inline]

Initializes the values based on CDB settings, logging properties, etc. All subscribing classes are notified of the new configuration, see LogConfigSubscriber#configureLogging(LogConfig).

This method can be called more than once: if some settings have changed, should be read in, and the logging classes should be notified of these changes. For example, the container could call this method when it gets notified that the logging configuration in the CDB has been changed at runtime.

Parameters:
cdbBeatsProperties if true then the default logger level values from the CDB override the properties (env vars). True is foreseen for dynamic updates from the CDB, whereas for the initial configuration it should be a false.
Exceptions:
LogConfigException if reading the configuration data failed and thus default values were used, or if there were problems during configuration even though some of the configuring went ok (best-effort approach).

References cdb, cdbComponentPaths, cdbLoggingConfigPath, CDBNAME_ComponentLogger, CDBNAME_LoggingConfig, configureDefaultLevelsFromProperties(), configureNamedLoggerLevelsFromProperties(), alma::cdbErrType::CDBRecordDoesNotExistEx::errorTrace, alma::cdbErrType::CDBXMLErrorEx::errorTrace, getLogConfigXml(), log(), loggingConfig, namedLoggerConfigs, notifySubscribers(), and storeNamedLoggerConfig().

Referenced by alma::acs::logging::ClientLogManager::ClientLogManager(), alma::acs::container::AcsContainer::initialize(), com::cosylab::acs::maci::manager::app::ManagerEngine::initializeManager(), com::cosylab::acs::maci::plug::ManagerProxyImpl::refresh_logging_config(), alma::acs::logging::config::LogConfigTest::testCDBValues(), alma::acs::logging::config::LogConfigTest::testInvalidCDB(), alma::acs::logging::config::LogConfigTest::testLockingRemoteLevel(), and alma::acs::logging::config::LogConfigTest::testSubscriberNotification().

boolean alma::acs::logging::config::LogConfig::isKnownLogger ( String  loggerName  )  [inline]

Checks if the given logger name is known, either for default or custom config.

The current LoggingConfigurable interface semantics don't allow configuration of a logger that does not yet exist. Therefore this method can be used to check first before calling getNamedLoggerConfig(String) or setNamedLoggerConfig(String, alma.acs.logging.config.LogConfig.LockableUnnamedLogger), which would automatically add a previously unknown logger.

Parameters:
loggerName 
Since:
ACS 7.0.2

References namedLoggerConfigs.

void alma::acs::logging::config::LogConfig::log ( Level  level,
String  msg,
Throwable  thr 
) [inline, protected]
void alma::acs::logging::config::LogConfig::notifySubscribers (  )  [inline, package]
void alma::acs::logging::config::LogConfig::removeSubscriber ( LogConfigSubscriber  subscriber  )  [inline]
boolean alma::acs::logging::config::LogConfig::renameNamedLoggerConfig ( String  oldLoggerName,
String  newLoggerName 
) [inline]

Renaming of a logger can occur for example when an ORB logger undergoes a name change as soon as the process name is determined by the container logger.

Renaming is not a regular part of a logger's life though. By the time that tools can look at the list of loggers, no renaming should occur any more.

Parameters:
oldLoggerName 
newLoggerName 
Returns:
true if the logger config was renamed. False for bad or unmatching parameters which result in no change.

References namedLoggerConfigs.

Referenced by alma::acs::logging::AcsLogger::setLoggerName().

void alma::acs::logging::config::LogConfig::setAndLockMinLogLevel ( AcsLogLevelDefinition  newLevel,
String  loggerName 
) [inline]

Locking a remote log level is currently needed only for the container to ensure that the ORB logger of the container in which the archive logger component runs is guaranteed to not produce any logs (which would lead to log record explosion through positive feedback).

The more abstract concept of locking log levels was chosen to keep the special scenario described above out of the logging config code.

Parameters:
newLevel small integer log level (IDL value wrapped by a Java enum)
loggerName 

References getNamedLoggerConfig(), alma::acs::logging::config::LogConfig::LockableUnnamedLogger::isLockedRemote, alma::acs::logging::config::LogConfig::LockableUnnamedLogger::lockRemote(), log(), namedLoggerConfigs, and setNamedLoggerConfig().

Referenced by alma::acs::logging::ClientLogManager::getLoggerForCorba(), alma::acs::logging::ClientLogManager::suppressCorbaRemoteLogging(), and alma::acs::logging::config::LogConfigTest::testLockingRemoteLevel().

void alma::acs::logging::config::LogConfig::setCDB ( DALOperations  cdb  )  [inline]

Sets the reference to the CDB, which will then be used for configuration. Before this method is called, default values are used instead of CDB values.

Note that the reference is only set, but the CDB is not read automatically; for this, call initialize(boolean).

Parameters:
cdb a reference to the CDB. Will be ignored if == null.

References log().

Referenced by alma::acs::container::AcsContainer::initialize(), com::cosylab::acs::maci::manager::app::ManagerEngine::initializeManager(), alma::acs::logging::config::LogConfigTest::testCDBValues(), alma::acs::logging::config::LogConfigTest::testGetLogConfigXml(), alma::acs::logging::config::LogConfigTest::testInvalidCDB(), and alma::acs::logging::config::LogConfigTest::testLockingRemoteLevel().

void alma::acs::logging::config::LogConfig::setCDBComponentPath ( String  compLoggerName,
String  path 
) [inline]

Sets the path to the CDB's node that is parent of the <log:UnnamedLogger/> component logger node. This call does not access the CDB.

Parameters:
compLoggerName the component logger name, e.g. MOUNT1.
path e.g. MACI/Components.

References cdbComponentPaths.

Referenced by alma::acs::logging::config::LogConfigTest::testCDBValues(), and alma::acs::logging::config::LogConfigTest::testGetLogConfigXml().

void alma::acs::logging::config::LogConfig::setCDBLoggingConfigPath ( String  path  )  [inline]
void alma::acs::logging::config::LogConfig::setDefaultMinLogLevel ( AcsLogLevelDefinition  newLevel  )  [inline]

Sets the given log level for centralized logging of log records for all loggers that don't have a custom configuration. All log config listeners.get notified of this change. The call is ignored for negative values of newLevel.

Parameters:
newLevel 

References loggingConfig, and notifySubscribers().

Referenced by com::cosylab::acs::maci::plug::ManagerProxyImpl::set_default_logLevels(), alma::acs::logging::RemoteLoggingTest::testConcurrentRemoteInitAndStop(), alma::acs::logging::ClientLogManagerTest::testConfigureApplicationLogger(), alma::acs::logging::config::LogConfigTest::testDynamicChanges(), and alma::acs::logging::ClientLogManagerTest::testSuppressCorbaRemoteLogging().

void alma::acs::logging::config::LogConfig::setDefaultMinLogLevelLocal ( AcsLogLevelDefinition  newLevel  )  [inline]

Sets the given log level for stdout printing of log records for all loggers that don't have a custom configuration. All log config listeners.get notified of this change. The call is ignored for negative values of newLevel.

Parameters:
newLevel 

References loggingConfig, and notifySubscribers().

Referenced by alma::acs::logging::LocalOnlyAcsLogger::getInstance(), com::cosylab::acs::maci::plug::ManagerProxyImpl::set_default_logLevels(), alma::acs::logging::RemoteLoggingTest::testConcurrentRemoteInitAndStop(), alma::acs::logging::ClientLogManagerTest::testConfigureApplicationLogger(), alma::acs::logging::config::LogConfigTest::testDynamicChanges(), and alma::acs::logging::ClientLogManagerTest::testSuppressCorbaRemoteLogging().

void alma::acs::logging::config::LogConfig::setInternalLogger ( Logger  logger  )  [inline]

Sets the Logger to be used by this class and dependent classes for internal tracing.

Note that in the current design of ClientLogManager and LogConfig, the Logger can not be provided already in the constructor, because the Logger first must be configured, which in turn requires a LogConfig instance. That's why we have this setter method.

Referenced by alma::acs::logging::ClientLogManager::ClientLogManager(), and alma::acs::logging::config::LogConfigTest::setUp().

void alma::acs::logging::config::LogConfig::setMinLogLevel ( AcsLogLevelDefinition  newLevel,
String  loggerName 
) [inline]
void alma::acs::logging::config::LogConfig::setMinLogLevelLocal ( AcsLogLevelDefinition  newLevel,
String  loggerName 
) [inline]
void alma::acs::logging::config::LogConfig::setNamedLoggerConfig ( String  loggerName,
UnnamedLogger  config 
) throws AcsJIllegalArgumentEx [inline]

We keep this method next to setNamedLoggerConfig(String, alma.acs.logging.config.LogConfig.LockableUnnamedLogger) in order to keep the LockableUnnamedLogger confined to this class. It may be exposed later, and this method could then be removed.

Parameters:
loggerName 
config 
Since:
ACS 7.0

References setNamedLoggerConfig().

void alma::acs::logging::config::LogConfig::setNamedLoggerConfig ( String  loggerName,
LockableUnnamedLogger  config 
) throws AcsJIllegalArgumentEx [inline]

Sets the given log levels for the named logger and notifies all listeners. Ignores this call if any of the parameters are null.

A copy of the supplied config is made to isolate the stored data from later modifications.

If loggerName is previously unknown, then this logger is added automatically to the list of known loggers. If this is not intended, check first using isKnownLogger(String).

Exceptions:
AcsJIllegalArgumentEx if the log level integers inside config are illegal.

References notifySubscribers(), and storeNamedLoggerConfig().

Referenced by com::cosylab::acs::maci::plug::ManagerProxyImpl::set_logLevels(), setAndLockMinLogLevel(), setMinLogLevel(), setMinLogLevelLocal(), and setNamedLoggerConfig().

void alma::acs::logging::config::LogConfig::storeNamedLoggerConfig ( String  loggerName,
LockableUnnamedLogger  config 
) [inline, private]

Method that guards namedLoggerConfigs.put(loggerName, config) and denies access if the old config is locked.

Parameters:
loggerName logger name, must not be null
config new level values, or null to "link" to default log levels.
See also:
namedLoggerConfigs

References alma::acs::logging::config::LogConfig::LockableUnnamedLogger::isLockedLocal, alma::acs::logging::config::LogConfig::LockableUnnamedLogger::isLockedRemote, log(), and namedLoggerConfigs.

Referenced by clearNamedLoggerConfig(), configureNamedLoggerLevelsFromProperties(), getNamedLoggerConfig(), initialize(), and setNamedLoggerConfig().


Member Data Documentation

The ACS CDB. This value is null unless it gets set in setCDB(DAL).

Referenced by getLogConfigXml(), and initialize().

Paths in the CDB to the element that contains component configuration with child elements of type UnnamedLogger. key = component logger name, value = path in the CDB to the Component configuration. Note that log levels given in the component configuration get overridden by named logger levels found in the container configuration, in case of conflicts.

This only applies to container log config, since for example the manager logging config does not deal with components.

Referenced by initialize(), LogConfig(), and setCDBComponentPath().

Path in the CDB to the element (container, manager etc) that contains a LoggingConfig child. From here we get process-wide settings, default log levels, and optional named logger levels. Note that named logger levels found here override those in cdbComponentPaths in case of conflict.

Referenced by initialize(), and setCDBLoggingConfigPath().

final String alma::acs::logging::config::LogConfig::CDBNAME_ComponentLogger = "ComponentLogger" [static, package]

In CDB queries for the ComponentLogger child of a component configuration we need the "LoggingConfig" string.

In the schema Components.xsd we are interested in the grand-child element ComponentLogger. The generated Java class corresponds to the type UnnamedLogger though. The element name is only present in the method name alma.maci.componentconfig.components.ComponentInfo::getComponentLogger which cannot be used to define a constant. Therefore we hardcode the name here.

Referenced by initialize().

final String alma::acs::logging::config::LogConfig::CDBNAME_LoggingConfig = LoggingConfig.class.getSimpleName() [static, package]

In CDB queries for the LoggingConfig child of a container or manager configuration we need the "LoggingConfig" string.

For type safety we get that name from the schema-generated castor class.

Referenced by initialize().

The logger for messages logged by this class. Note that this field will be null at first, until the Logger gets provided, so better use log(Level, String, Throwable) for safe access.

Referenced by log().

The schema-generated logging config, either with default values, or read from the CDB. The log levels can also be changed by properties (env var peers) and dynamically.

Referenced by configureDefaultLevelsFromProperties(), getCentralizedLogger(), getDefaultMinLogLevel(), getDefaultMinLogLevelLocal(), getDispatchPacketSize(), getFlushPeriodSeconds(), getImmediateDispatchLevel(), getMaxLogQueueSize(), getNamedLoggerConfig(), initialize(), LogConfig(), setDefaultMinLogLevel(), and setDefaultMinLogLevelLocal().

Logger names and optionally associated log levels. Loggers that use default levels are stored with their name (map key), but a null value for the configuration is associated with them.

Actual named logger configurations are stored as the map values, and can come from

key = [String] logger name, value = [LockableUnnamedLogger or null] level config

Referenced by getLoggerNames(), getNamedLoggerConfig(), hasCustomConfig(), initialize(), isKnownLogger(), LogConfig(), renameNamedLoggerConfig(), setAndLockMinLogLevel(), and storeNamedLoggerConfig().

final String alma::acs::logging::config::LogConfig::PROPERTYNAME_MIN_LOG_LEVEL = "ACS.log.minlevel.remote" [static]
final String alma::acs::logging::config::LogConfig::PROPERTYNAME_NAMED_LOGGER_LEVELS = "ACS.log.minlevel.namedloggers" [static]

Using this property, we can configure named loggers for processes other than containers and manager, for which there is no logging configuration in the CDB. It is not expected to be used widely, which excuses the not so intuitive stuffing of data into a single property.

Example:

-DACS.log.minlevel.namedloggers="hibernateSQL@CDB-RDB=2,3:hibernate@CDB-RDB=5,5"

configures two loggers: "hibernateSQL@CDB-RDB" will use local log level 2 and remote level 3, while "hibernate@CDB-RDB" will use local and remote level 5.

Referenced by configureNamedLoggerLevelsFromProperties().

Subscribers get notified of logging config changes

Referenced by addSubscriber(), LogConfig(), notifySubscribers(), and removeSubscriber().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2