com.metamatrix.common.log.config
Class BasicLogConfiguration

java.lang.Object
  extended by com.metamatrix.common.log.config.BasicLogConfiguration
All Implemented Interfaces:
LogConfiguration, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

public class BasicLogConfiguration
extends java.lang.Object
implements LogConfiguration, java.io.Serializable, java.lang.Cloneable

Basic, default implementation of the LogConfiguration interface. This class contains the int logging level, as well as a Collection of String discarded contexts (logging contexts which will not be logged.) This class also contains static final String constants specifying the two property names whose values completely describe a LogConfiguration, plus static utility methods for converting a LogConfiguration object to and from a Properties object representation.

See Also:
Serialized Form

Field Summary
static java.lang.String CONTEXT_DELIMETER
          This String should separate each of the contexts in the String value for the property LOG_CONTEXT_PROPERTY_NAME.
static java.lang.String LOG_CONTEXT_PROPERTY_NAME
          The name of the System property that contains the set of comma-separated context names for messages not to be recorded.
static java.lang.String LOG_LEVEL_PROPERTY_NAME
          The name of the System property that contains the message level for the LogManager.
 
Constructor Summary
BasicLogConfiguration()
           
BasicLogConfiguration(java.util.Collection contexts, int msgLevel)
           
BasicLogConfiguration(int msgLevel)
           
BasicLogConfiguration(LogConfiguration currentLogConfig)
           
 
Method Summary
 java.lang.Object clone()
          Clone the object.
 int compareTo(java.lang.Object obj)
          Compares this object to another.
static LogConfiguration createLogConfiguration(java.util.Properties props)
           Creates a non-null LogConfiguration from the given properties.
 void discardContext(java.lang.String context)
          Specify that messages with the input context should be discarded and not recorded.
 void discardContexts(java.util.Collection contexts)
          Direct the log configuration to discard the given contexts and not record them.
 boolean equals(java.lang.Object obj)
          Returns true if the specified object is semantically equal to this instance.
 java.util.Set getDiscardedContexts()
          Obtain the set of contexts for messages that are to be discarded.
static java.util.Properties getLogConfigurationProperties(LogConfiguration logConfiguration)
          Creates a Properties object containing the two name/value pairs which define a LogConfiguration, parsed from the given LogConfiguration object.
 int getMessageLevel()
          Get the level of detail of messages that are currently being recorded.
 boolean isMessageToBeRecorded(java.lang.String context, int msgLevel)
           
 void recordAllContexts()
          Direct the log configuration to record all known logging contexts.
 void recordContexts(java.util.Collection contexts)
          Direct the log configuration to record only these contexts.
 void setMessageLevel(int level)
          Direct the log configuration to record messages of the given level or above.
 java.lang.String toString()
          String representation of logging configuration.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG_LEVEL_PROPERTY_NAME

public static final java.lang.String LOG_LEVEL_PROPERTY_NAME
The name of the System property that contains the message level for the LogManager. This is an optional property that defaults to '3'.

See Also:
Constant Field Values

LOG_CONTEXT_PROPERTY_NAME

public static final java.lang.String LOG_CONTEXT_PROPERTY_NAME

The name of the System property that contains the set of comma-separated context names for messages not to be recorded. A message context is simply some string that identifies something about the component that generates the message. The value for the contexts is application specific.

This is an optional property that defaults to no contexts (i.e., messages with any context are recorded).

See Also:
Constant Field Values

CONTEXT_DELIMETER

public static final java.lang.String CONTEXT_DELIMETER
This String should separate each of the contexts in the String value for the property LOG_CONTEXT_PROPERTY_NAME. For example, if this delimiter were a comma, the value for the property might be something like "CONFIG,QUERY,CONFIGURATION_ADAPTER".

See Also:
Constant Field Values
Constructor Detail

BasicLogConfiguration

public BasicLogConfiguration(java.util.Collection contexts,
                             int msgLevel)

BasicLogConfiguration

public BasicLogConfiguration()

BasicLogConfiguration

public BasicLogConfiguration(int msgLevel)

BasicLogConfiguration

public BasicLogConfiguration(LogConfiguration currentLogConfig)
Method Detail

createLogConfiguration

public static LogConfiguration createLogConfiguration(java.util.Properties props)
                                               throws LogConfigurationException

Creates a non-null LogConfiguration from the given properties. A LogConfiguration with default behavior (using default, no-arg constructor) is created if one or more of the two necessary property values are missing, or if the Properties parameter is null.

The two properties are LOG_LEVEL_PROPERTY_NAME and LOG_CONTEXT_PROPERTY_NAME

Parameters:
props - Properties which should have values for the properties LOG_LEVEL_PROPERTY_NAME and LOG_CONTEXT_PROPERTY_NAME
Returns:
LogConfiguration object representing the property values
Throws:
LogConfigurationException - this currently is not being thrown, but remains in the method signature because it is very possible the implementation of this method may change. It should be noted that if any unexpected error happens (such as an invalid property value) a default LogConfiguration is created instead of what may be expected.

getLogConfigurationProperties

public static java.util.Properties getLogConfigurationProperties(LogConfiguration logConfiguration)
                                                          throws LogConfigurationException

Creates a Properties object containing the two name/value pairs which define a LogConfiguration, parsed from the given LogConfiguration object.

The two properties are LOG_LEVEL_PROPERTY_NAME and LOG_CONTEXT_PROPERTY_NAME

Parameters:
logConfiguration - LogConfiguration which you want a Properties object representation of. This parameter may be null, in which case an empty Properties object will be returned.
Returns:
Properties object representing LogConfiguration parameter. An empty Properties object is return if the parameter is null. Otherwise, the Properties object will have a value for the property LOG_LEVEL_PROPERTY_NAME, and may have a value for the property LOG_CONTEXT_PROPERTY_NAME, if the parameter logConfiguration had any discarded log contexts in it.
Throws:
LogConfigurationException - this currently is not being thrown, but remains in the method signature because it is very possible the implementation of this method may change.

getDiscardedContexts

public java.util.Set getDiscardedContexts()
Obtain the set of contexts for messages that are to be discarded. If this method returns an empty set, then messages in all contexts are being recorded; if not empty, then messages with a context in the returned set are discarded and messages for all other contexts recorded.

Specified by:
getDiscardedContexts in interface LogConfiguration
Returns:
the set of contexts for messages that are to be discarded

discardContext

public void discardContext(java.lang.String context)
Specify that messages with the input context should be discarded and not recorded.

Specified by:
discardContext in interface LogConfiguration
Parameters:
context - the context to add to the set; this method does nothing if the reference is null

getMessageLevel

public int getMessageLevel()
Get the level of detail of messages that are currently being recorded.

Specified by:
getMessageLevel in interface LogConfiguration
Returns:
the level of detail

compareTo

public int compareTo(java.lang.Object obj)
Compares this object to another. If the specified object is an instance of the MetadataID class, then this method compares the name; otherwise, it throws a ClassCastException (as instances are comparable only to instances of the same class). Note: this method is consistent with equals(), meaning that (compare(x, y)==0) == (x.equals(y)).

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - the object that this instance is to be compared to.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object, respectively.
Throws:
java.lang.IllegalArgumentException - if the specified object reference is null
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this instance.

equals

public boolean equals(java.lang.Object obj)
Returns true if the specified object is semantically equal to this instance. Note: this method is consistent with compareTo().

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object that this instance is to be compared to.
Returns:
whether the object is equal to this object.

toString

public java.lang.String toString()
String representation of logging configuration.

Overrides:
toString in class java.lang.Object
Returns:
String representation

clone

public java.lang.Object clone()
Description copied from interface: LogConfiguration
Clone the object.

Specified by:
clone in interface LogConfiguration
Overrides:
clone in class java.lang.Object
Returns:

recordAllContexts

public void recordAllContexts()
Direct the log configuration to record all known logging contexts.

Specified by:
recordAllContexts in interface LogConfiguration

discardContexts

public void discardContexts(java.util.Collection contexts)
Direct the log configuration to discard the given contexts and not record them.

Specified by:
discardContexts in interface LogConfiguration
Parameters:
contexts - the collection of contexts that should be discarded.

recordContexts

public void recordContexts(java.util.Collection contexts)
Direct the log configuration to record only these contexts.

Specified by:
recordContexts in interface LogConfiguration
Parameters:
contexts - the contexts that should be recorded.

setMessageLevel

public void setMessageLevel(int level)
Direct the log configuration to record messages of the given level or above.

Specified by:
setMessageLevel in interface LogConfiguration
Parameters:
level - the lowest level to record.

isMessageToBeRecorded

public boolean isMessageToBeRecorded(java.lang.String context,
                                     int msgLevel)
Specified by:
isMessageToBeRecorded in interface LogConfiguration


Copyright © 2009. All Rights Reserved.