alma::acs::logging::ClientLogManager Class Reference

Inheritance diagram for alma::acs::logging::ClientLogManager:
Inheritance graph
[legend]
Collaboration diagram for alma::acs::logging::ClientLogManager:
Collaboration graph
[legend]

List of all members.

Classes

class  AcsLoggerInfo

Public Types

enum  LoggerOwnerType {
  ContainerLogger, ComponentLogger, OrbLogger, OtherLogger,
  UnknownLogger
}

Public Member Functions

void configureLogging (LogConfig logConfig)
LogConfig getLogConfig ()
boolean initRemoteLogging (ORB orb, Manager manager, int managerHandle, boolean retry)
void suppressRemoteLogging ()
void suppressCorbaRemoteLogging ()
AcsLogger getLoggerForCorba (String corbaName, boolean autoConfigureContextName)
AcsLogger getLoggerForContainer (String containerName)
AcsLogger getLoggerForComponent (String componentName)
AcsLogger getLoggerForApplication (String loggerName, boolean enableRemoteLogging)
void shutdown (boolean wait)
void flushAll ()

Static Public Member Functions

static synchronized
ClientLogManager 
getAcsLogManager ()

Protected Member Functions

 ClientLogManager ()
void prepareRemoteLogging ()
void disableRemoteLogging ()
AcsLogServiceOperations getLogService (Manager manager, int managerHandle) throws ComponentNotAlreadyActivatedEx, CannotGetComponentEx, NoPermissionEx, ComponentConfigurationNotFoundEx

Protected Attributes

volatile DispatchingLogQueue logQueue

Private Member Functions

AcsLoggingHandler addRemoteHandler (AcsLogger logger)
StdOutConsoleHandler addLocalHandler (AcsLogger logger)
AcsLogger getAcsLogger (String loggerName, LoggerOwnerType loggerOwnerType)
void setProcessName (String processName)

Private Attributes

final LogConfig sharedLogConfig
volatile String logServiceName
volatile int flushPeriodSeconds
final Map< String, AcsLoggerInfologgers = new HashMap<String, AcsLoggerInfo>()
Logger parentRemoteLogger
final ReentrantLock logQueueLock = new ReentrantLock()
RemoteLogDispatcher logDispatcher
final Logger m_internalLogger
boolean DEBUG = Boolean.getBoolean("alma.acs.logging.verbose")
boolean LOG_BIN_TYPE = Boolean.getBoolean("ACS.loggingBin")
String processName
final ReentrantLock processNameLock = new ReentrantLock()
volatile boolean suppressCorbaRemoteLogging = false

Static Private Attributes

static volatile ClientLogManager s_instance

Detailed Description

This class provides methods for getting the loggers for components and containers. Both the loggers and the handlers are organized in a hierarchical namespace so that children may inherit some properties from their parents in the namespace.

To set the policy for remote logging, either initRemoteLogging(ORB, Manager, int, boolean) or suppressRemoteLogging() must be called. As long as none of these methods are called, it is assumed that remote logging will be initialized at some point later, and all log messages that are meant for remote logging will be stored in a queue. suppressRemoteLogging will throw away this queue, while initRemoteLogging will send all queued log records to the remote logger.

Since ACS 7.0, this class acts pretty much as a replacement for the JDK's LogManager and the AcsLogManager} subclass.
If needed, we should investigate how to support the JMX logger management via java.util.logging.LoggingMXBean} which is useless now.

Author:
hsommer

Member Enumeration Documentation

Enumerator:
ContainerLogger 
ComponentLogger 
OrbLogger 
OtherLogger 
UnknownLogger 

Constructor & Destructor Documentation

alma::acs::logging::ClientLogManager::ClientLogManager (  )  [inline, protected]

Member Function Documentation

StdOutConsoleHandler alma::acs::logging::ClientLogManager::addLocalHandler ( AcsLogger  logger  )  [inline, private]

Adds a local logging handler to the provided logger. Unlike with remote handlers in prepareRemoteLogging(), for local handlers we don't allow removing and re-adding the handlers later.

Note that this method does not require logger to be already registered in loggers}, but if it is, then the new StdOutConsoleHandler is set in the map's AcsLoggerInfo as well.

Parameters:
logger logger to be set up for local logging
Returns:
the local handler that was added to the logger.

References alma::acs::logging::AcsLogger::getLoggerName(), alma::acs::logging::ClientLogManager::AcsLoggerInfo::localHandler, loggers, and sharedLogConfig.

Referenced by getAcsLogger(), and getLoggerForApplication().

AcsLoggingHandler alma::acs::logging::ClientLogManager::addRemoteHandler ( AcsLogger  logger  )  [inline, private]

Attaches a remote log handler to the given logger, if remote logging has not been suppressed.

Note that this method does not require logger to be already registered in loggers}, but if it is, then the new AcsLoggingHandler is set in the map's AcsLoggerInfo as well.

Parameters:
logger logger to be set up for remote logging
Returns:
the remote handler that was added to the logger.

References alma::acs::logging::AcsLogger::getLoggerName(), loggers, logQueue, alma::acs::logging::ClientLogManager::AcsLoggerInfo::remoteHandler, and sharedLogConfig.

Referenced by getAcsLogger(), and prepareRemoteLogging().

void alma::acs::logging::ClientLogManager::configureLogging ( LogConfig  logConfig  )  [inline]
void alma::acs::logging::ClientLogManager::disableRemoteLogging (  )  [inline, protected]

Removes, closes, and nulls all remote handlers, so that no more records are put into the queue, and queue and remote handlers can be garbage collected.

GC of the queue can be an advantage when logs have been queued for remote sending, but then instead of connecting to the remote logger, we get a call to suppressRemoteLogging(). All messages have been logged locally anyway, so in this case we want to clean up all these LogRecords.

References alma::acs::logging::AcsLoggingHandler::close(), alma::acs::logging::ClientLogManager::AcsLoggerInfo::logger, loggers, and alma::acs::logging::ClientLogManager::AcsLoggerInfo::remoteHandler.

Referenced by shutdown(), and suppressRemoteLogging().

void alma::acs::logging::ClientLogManager::flushAll (  )  [inline]

Flushes the remote log queue completely and returns only when it's done.

References alma::acs::logging::DispatchingLogQueue::flushAllAndWait(), and logQueue.

Referenced by shutdown().

AcsLogger alma::acs::logging::ClientLogManager::getAcsLogger ( String  loggerName,
LoggerOwnerType  loggerOwnerType 
) [inline, private]

Creates or reuses a logger, normally with both a local and a remote handler attached. If remote logging is suppressed then no remote handler is attached.

Logger names must be unique. If the requested logger name matches a given logger of the same LoggerOwnerType then that logger is returned. If however a logger of a different type is matched, then a name uniqueness violation is avoided by appending small integer numbers to the logger name. Therefore the name of the returned Logger may be different from loggerName! The idea of this strategy is that uniqueness of component names will be enforced by the system, while a component may in sick cases have the name of a container or the orb logger.

Parameters:
loggerName The unique logger name
loggerOwnerType enum for the type of the logger owner. With ACS 7.0, this replaces the namespace strings previously prepended to the logger names.
Returns:
Exceptions:
IllegalArgumentException if loggerName is null or empty

References addLocalHandler(), addRemoteHandler(), DEBUG, alma::acs::logging::ClientLogManager::AcsLoggerInfo::localHandler, alma::acs::logging::ClientLogManager::AcsLoggerInfo::logger, alma::acs::logging::ClientLogManager::AcsLoggerInfo::loggerOwnerType, loggers, parentRemoteLogger, processName, alma::acs::logging::ClientLogManager::AcsLoggerInfo::remoteHandler, alma::acs::logging::AcsLogger::setProcessName(), alma::acs::logging::AcsLogger::setSourceObject(), and sharedLogConfig.

Referenced by ClientLogManager(), getLoggerForApplication(), getLoggerForComponent(), getLoggerForContainer(), and getLoggerForCorba().

static synchronized ClientLogManager alma::acs::logging::ClientLogManager::getAcsLogManager (  )  [inline, static]

Singleton accessor.

TODO: rename, because now that we have class AcsLogManager, this method name is confusing.

Returns:
ClientLogManager

References ClientLogManager(), and s_instance.

Referenced by alma::acs::logging::ClientLogManagerTest::setUp().

LogConfig alma::acs::logging::ClientLogManager::getLogConfig (  )  [inline]

Gets the LogConfig object that is shared between the ClientLogManager singleton and any other objects in the process (e.g. Java container or manager classes, Loggers, Handlers).

References sharedLogConfig.

Referenced by prepareRemoteLogging(), alma::acs::logging::RemoteLoggingTest::testConcurrentRemoteInitAndStop(), alma::acs::logging::ClientLogManagerTest::testConfigureApplicationLogger(), and alma::acs::logging::ClientLogManagerTest::testSuppressCorbaRemoteLogging().

AcsLogger alma::acs::logging::ClientLogManager::getLoggerForApplication ( String  loggerName,
boolean  enableRemoteLogging 
) [inline]

Gets a logger for an application (which is not an ACS component itself), e.g. a GUI application using the ACS ComponentClient.

Parameters:
loggerName the logger name, should identify the application or the particular logger that gets requested.
enableRemoteLogging if true (generally recommended), the returned logger is set up to send the logs to the remote log service, as it always happens for container and component loggers. <emph>This will only work if initRemoteLogging(ORB, Manager, int, boolean) is also called, which happens automatically in ComponentClient. For a standalone application that is not ACS-aware (no manager known etc), remote logging is not available even with enableRemoteLogging == true.</emph>
Returns:
a configured Logger

References addLocalHandler(), alma::acs::logging::AcsLogger::configureLevels(), alma::acs::logging::AcsLogger::createUnconfiguredLogger(), getAcsLogger(), alma::acs::logging::config::LogConfig::getNamedLoggerConfig(), setProcessName(), and sharedLogConfig.

Referenced by alma::acs::logging::RemoteLoggingTest::testConcurrentRemoteInitAndStop(), alma::acs::logging::ClientLogManagerTest::testConfigureApplicationLogger(), and alma::acs::logging::RemoteLoggingTest::testSimpleRemoteLogging().

AcsLogger alma::acs::logging::ClientLogManager::getLoggerForComponent ( String  componentName  )  [inline]

Gets a logger object to be used by a component.

This method is not supposed to be accessed directly in the component implementation. Instead, the implementation of alma.acs.container.ContainerServices should call this method.

Parameters:
componentName component name (sufficiently qualified to be unique in the system or log domain)
Returns:
AcsLogger

References getAcsLogger().

Referenced by alma::acs::logging::ClientLogManagerTest::testLoggerNameUniqueness().

AcsLogger alma::acs::logging::ClientLogManager::getLoggerForContainer ( String  containerName  )  [inline]
AcsLogger alma::acs::logging::ClientLogManager::getLoggerForCorba ( String  corbaName,
boolean  autoConfigureContextName 
) [inline]

Gets a logger to be used by ORB and POA classes, or by hibernate. The logger is connected to the central ACS logger.

rename this method to accommodate non-corba frameworks into which we insert ACS loggers, such as hibernate, see org.slf4j.impl.ACSLoggerFactory.

For hibernate loggers, the logger automatically receives an initial custom log level configuration, to avoid jamming the log system with hibernate logs. The applied custom log level is the maximum of the default log level and WARNING. Note that the hibernate logger can still be set to a more verbose level by giving it a custom log config in the CDB, or dynamically using logLevelGUI etc.

Instead of this hard coded and probably confusing application of a custom log level, the CDB should offer a central configuration option for all jacorb, hibernate etc loggers, independently of the process (container or manager etc).

Parameters:
corbaName e.g. jacorb. rename it.
autoConfigureContextName if true, the context (e.g. container name) will be appended to this logger's name as soon as it is available, changing the logger name to something like jacorb.

References alma::acs::logging::AcsLogger::addIgnoreLogs(), getAcsLogger(), alma::acs::logging::config::LogConfig::getDefaultMinLogLevel(), alma::acs::logging::config::LogConfig::getDefaultMinLogLevelLocal(), alma::acs::logging::config::LogConfig::hasCustomConfig(), loggers, m_internalLogger, alma::acs::logging::ClientLogManager::AcsLoggerInfo::needsProcessNameUpdate, processName, processNameLock, alma::acs::logging::config::LogConfig::setAndLockMinLogLevel(), alma::acs::logging::config::LogConfig::setMinLogLevel(), alma::acs::logging::config::LogConfig::setMinLogLevelLocal(), sharedLogConfig, and suppressCorbaRemoteLogging().

Referenced by alma::acs::logging::ClientLogManagerTest::testLoggerNameUniqueness(), and alma::acs::logging::ClientLogManagerTest::testSuppressCorbaRemoteLogging().

AcsLogServiceOperations alma::acs::logging::ClientLogManager::getLogService ( Manager  manager,
int  managerHandle 
) throws ComponentNotAlreadyActivatedEx, CannotGetComponentEx, NoPermissionEx, ComponentConfigurationNotFoundEx [inline, protected]

This method is broken out from initRemoteLogging(ORB, Manager, int, boolean) to allow mock implementation by tests without a functional manager object. Note that module acsjlog comes before jmanager.

Since ACS 8.0.1 we use an ACS-specific subtype of LogOperations to avoid the marshalling to Corba Any.

Reimplemented in alma::acs::logging::RemoteLoggingTest::ClientLogManagerStandalone.

References logServiceName.

Referenced by initRemoteLogging().

boolean alma::acs::logging::ClientLogManager::initRemoteLogging ( ORB  orb,
Manager  manager,
int  managerHandle,
boolean  retry 
) [inline]

Enables loggers to send log records to the central ACS logger service. Tries to connect to the log service using the supplied ACS manager. As long as this connection fails, this method can sleep for 10 seconds and then try to connect again, if the parameter retry is true. Total retries are limited to 5, to detect a permanent problem before the log queue overflows.

Execution time can be significant, so consider calling this method in a separate thread (which has no negative effect on the logging since all log records are cached and automatically sent off once the log service is available). Use a daemon thread to avoid shutdown problems if this method still hangs in the login loop.

When the log service is obtained, the log queue used for remote logging will be flushed periodically to the log service unless an otherwise triggered flush has done this already. The default period is 10 seconds, but can be overridden in the CDB.

Parameters:
orb the ORB used in this JVM
manager the ACS manager
managerHandle handle assigned by the ACS Manager for this client
retry if true, a failing connection to the log service will trigger up to 5 other attempts, every 10 seconds.
Returns:
true if remote logging was initialized successfully
See also:
shutdown(boolean)

References alma::acs::logging::DispatchingLogQueue::flushAllAndWait(), flushPeriodSeconds, getLogService(), LOG_BIN_TYPE, logDispatcher, logQueue, logQueueLock, logServiceName, m_internalLogger, prepareRemoteLogging(), alma::acs::logging::DispatchingLogQueue::setPeriodicFlushing(), and alma::acs::logging::DispatchingLogQueue::setRemoteLogDispatcher().

Referenced by alma::acs::logging::RemoteLoggingTest::initRemoteLogging().

void alma::acs::logging::ClientLogManager::prepareRemoteLogging (  )  [inline, protected]
void alma::acs::logging::ClientLogManager::setProcessName ( String  processName  )  [inline, private]

Takes the process name and overwrites previous names, and updates all Loggers which are waiting to get their overly simple name enriched. The new name will be the old name + @ + processName.

The update mechanism ensures that the process name will eventually be set also on loggers which were created before the process name was known, e.g. component logger created before container logger. check if we still need the process name appended to the logger name, now that we have a separate field for it in AcsLogger.

Parameters:
name 

References alma::acs::logging::ClientLogManager::AcsLoggerInfo::logger, loggers, m_internalLogger, alma::acs::logging::ClientLogManager::AcsLoggerInfo::needsProcessNameUpdate, processNameLock, alma::acs::logging::AcsLogger::setLoggerName(), and alma::acs::logging::AcsLogger::setProcessName().

Referenced by getLoggerForApplication(), and getLoggerForContainer().

void alma::acs::logging::ClientLogManager::shutdown ( boolean  wait  )  [inline]

Allows to suppress remote logging of Corba/ORB logger(s). Internally this suppression is handled using log level changes that cannot be undone by other log level changes. Generally remote logging remains enabled though, which makes this method quite different from suppressRemoteLogging()}.

Application code such as components must not call this method!

References loggers, alma::acs::logging::config::LogConfig::setAndLockMinLogLevel(), and sharedLogConfig.

Referenced by getLoggerForCorba().

void alma::acs::logging::ClientLogManager::suppressRemoteLogging (  )  [inline]

Suppresses remote logging. If log messages destined for remote logging have not been sent to the central log service yet (e.g. because initRemoteLogging has not been called, or because of sending failures), these log messages will be lost for remote logging. Log messages produced after this call will not even be queued for remote logging.

This method should only be called by special ALMA applications such as the Observation Preparation tool, which runs stand-alone, with all containers, managers, etc. in one JVM. In this case, no central logger is available, and all loggers which normally send their output to the central logger should be limited to local logging (stdout).

It is possible (probably not useful in real life) to re-enable remote logging later, by calling initRemoteLogging.

References disableRemoteLogging(), logQueue, and logQueueLock.

Referenced by alma::acs::logging::ClientLogManagerTest::testSuppressRemoteLoggingAndCheckGC().


Member Data Documentation

boolean alma::acs::logging::ClientLogManager::DEBUG = Boolean.getBoolean("alma.acs.logging.verbose") [private]

for testing

Referenced by ClientLogManager(), getAcsLogger(), and shutdown().

The time in seconds between the periodic log queue flushings

Referenced by configureLogging(), and initRemoteLogging().

boolean alma::acs::logging::ClientLogManager::LOG_BIN_TYPE = Boolean.getBoolean("ACS.loggingBin") [private]

Referenced by initRemoteLogging().

The log dispatcher object serves as a flag for whether remote logging has been activated via initRemoteLogging(ORB, Manager, int, boolean).

Referenced by initRemoteLogging().

final Map<String, AcsLoggerInfo> alma::acs::logging::ClientLogManager::loggers = new HashMap<String, AcsLoggerInfo>() [private]

We store all loggers in this map instead of giving them to LogManager which does not allow to remove loggers and would thus prevent component loggers from being garbage collected.

Referenced by addLocalHandler(), addRemoteHandler(), disableRemoteLogging(), getAcsLogger(), getLoggerForCorba(), prepareRemoteLogging(), setProcessName(), and suppressCorbaRemoteLogging().

The log queue can be null if remote logging has been suppressed. Otherwise it is non-null even if remote logging is not active, because it stores the records to be sent off later.

Referenced by addRemoteHandler(), configureLogging(), flushAll(), initRemoteLogging(), prepareRemoteLogging(), shutdown(), and suppressRemoteLogging().

final ReentrantLock alma::acs::logging::ClientLogManager::logQueueLock = new ReentrantLock() [private]

The (CORBA-) name of the remote logging service to which logs will be sent

Referenced by configureLogging(), getLogService(), and initRemoteLogging().

Logger used by the classes in this logging package. TODO: allow container or client to replace this logger with their own logger, because these classes belong to their respective process.

Referenced by ClientLogManager(), configureLogging(), getLoggerForCorba(), initRemoteLogging(), and setProcessName().

Parent logger of all remote loggers. Not really needed any more now that handlers are not shared.

Referenced by ClientLogManager(), and getAcsLogger().

The process name gets used as a data field in the log record, and also gets appended to the name for the Corba logger, so that different ORB instances in the system can be distinguished.

Referenced by getAcsLogger(), and getLoggerForCorba().

final ReentrantLock alma::acs::logging::ClientLogManager::processNameLock = new ReentrantLock() [private]

instance of a singleton

Referenced by getAcsLogManager(), and shutdown().

The logging configurator shared by various classes of this package

Referenced by addLocalHandler(), addRemoteHandler(), ClientLogManager(), getAcsLogger(), getLogConfig(), getLoggerForApplication(), getLoggerForCorba(), and suppressCorbaRemoteLogging().

If true then the Corba (ORB) logger will not send logs to the Log service.

Referenced by alma::acs::logging::ClientLogManagerTest::testSuppressCorbaRemoteLogging().


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

Generated by  doxygen 1.6.2