JBoss Log Manager 1.2.0.GA

org.jboss.logmanager
Class LogContext

java.lang.Object
  extended by org.jboss.logmanager.LogContext

public final class LogContext
extends Object

A logging context, for producing isolated logging environments.


Field Summary
static LogContextSelector DEFAULT_LOG_CONTEXT_SELECTOR
          The default log context selector, which always returns the system log context.
 
Method Summary
static LogContext create()
          Create a new log context.
<V> V
getAttachment(String loggerName, Logger.AttachmentKey<V> key)
          Get a logger attachment for a logger name, if it exists.
 Level getLevelForName(String name)
          Get the level for a name.
static LogContext getLogContext()
          Get the currently active log context.
 Logger getLogger(String name)
          Get a logger with the given name from this logging context.
 Logger getLoggerIfExists(String name)
          Get a logger with the given name from this logging context, if a logger node exists at that location.
 LoggingMXBean getLoggingMXBean()
          Get the LoggingMXBean associated with this log context.
static LogContext getSystemLogContext()
          Get the system log context.
 void registerLevel(Level level)
          Register a level instance with this log context.
static void setLogContextSelector(LogContextSelector newSelector)
          Set a new log context selector.
 void unregisterLevel(Level level)
          Unregister a previously registered level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOG_CONTEXT_SELECTOR

public static final LogContextSelector DEFAULT_LOG_CONTEXT_SELECTOR
The default log context selector, which always returns the system log context.

Method Detail

create

public static LogContext create()
Create a new log context. If a security manager is installed, the caller must have the "createLogContext" RuntimePermission to invoke this method.

Returns:
a new log context

getLogger

public Logger getLogger(String name)
Get a logger with the given name from this logging context.

Parameters:
name - the logger name
Returns:
the logger instance
See Also:
LogManager.getLogger(String)

getLoggerIfExists

public Logger getLoggerIfExists(String name)
Get a logger with the given name from this logging context, if a logger node exists at that location.

Parameters:
name - the logger name
Returns:
the logger instance, or null if no such logger node exists

getAttachment

public <V> V getAttachment(String loggerName,
                           Logger.AttachmentKey<V> key)
Get a logger attachment for a logger name, if it exists.

Type Parameters:
V - the attachment value type
Parameters:
loggerName - the logger name
key - the attachment key
Returns:
the attachment or null if the logger or the attachment does not exist

getLoggingMXBean

public LoggingMXBean getLoggingMXBean()
Get the LoggingMXBean associated with this log context.

Returns:
the LoggingMXBean instance

getLevelForName

public Level getLevelForName(String name)
                      throws IllegalArgumentException
Get the level for a name.

Parameters:
name - the name
Returns:
the level
Throws:
IllegalArgumentException - if the name is not known

registerLevel

public void registerLevel(Level level)
Register a level instance with this log context. The level can then be looked up by name. Only a weak reference to the level instance will be kept. Any previous level registration for the given level's name will be overwritten.

Parameters:
level - the level to register

unregisterLevel

public void unregisterLevel(Level level)
Unregister a previously registered level. Log levels that are not registered may still be used, they just will not be findable by name.

Parameters:
level - the level to unregister

getSystemLogContext

public static LogContext getSystemLogContext()
Get the system log context.

Returns:
the system log context

getLogContext

public static LogContext getLogContext()
Get the currently active log context.

Returns:
the currently active log context

setLogContextSelector

public static void setLogContextSelector(LogContextSelector newSelector)
Set a new log context selector. If a security manager is installed, the caller must have the "setLogContextSelector" RuntimePermission to invoke this method.

Parameters:
newSelector - the new selector.

JBoss Log Manager 1.2.0.GA

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.