FileDocCategorySizeDatePackage
PolicyLogger.javaAPI DocExample16853Tue May 29 16:56:38 BST 2007com.sun.xml.ws.policy.privateutil

PolicyLogger

public final class PolicyLogger extends Object
This is a helper class that provides some conveniece methods wrapped around the standard {@link java.util.logging.Logger} interface.
author
Marek Potociar

Fields Summary
private static final String
LOGGING_SUBSYSTEM_NAME
If we run with JAX-WS, we are using its logging domain (appended with ".wspolicy"). Otherwise we default to "wspolicy".
private static final Level
METHOD_CALL_LEVEL_VALUE
private final String
componentClassName
private final Logger
logger
Constructors Summary
private PolicyLogger(String componentName)
Prevents creation of a new instance of this PolicyLogger

        this.componentClassName = "[" + componentName + "] ";
        this.logger = java.util.logging.Logger.getLogger(LOGGING_SUBSYSTEM_NAME);
    
Methods Summary
public voidconfig(java.lang.String message)

        if (!this.logger.isLoggable(Level.CONFIG)) {
            return;
        }
        logger.logp(Level.CONFIG, componentClassName, getCallerMethodName(), message);
    
public voidconfig(java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(Level.CONFIG)) {
            return;
        }
        logger.logp(Level.CONFIG, componentClassName, getCallerMethodName(), message, thrown);
    
public voidentering()

        if (!this.logger.isLoggable(METHOD_CALL_LEVEL_VALUE)) {
            return;
        }
        
        logger.entering(componentClassName, getCallerMethodName());
    
public voidentering(java.lang.Object parameters)

        if (!this.logger.isLoggable(METHOD_CALL_LEVEL_VALUE)) {
            return;
        }
        
        logger.entering(componentClassName, getCallerMethodName(), parameters);
    
public voidexiting()

        if (!this.logger.isLoggable(METHOD_CALL_LEVEL_VALUE)) {
            return;
        }
        logger.exiting(componentClassName, getCallerMethodName());
    
public voidexiting(java.lang.Object result)

        if (!this.logger.isLoggable(METHOD_CALL_LEVEL_VALUE)) {
            return;
        }
        logger.exiting(componentClassName, getCallerMethodName(), result);
    
public voidfine(java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(Level.FINE)) {
            return;
        }
        logger.logp(Level.FINE, componentClassName, getCallerMethodName(), message, thrown);
    
public voidfine(java.lang.String message)

        if (!this.logger.isLoggable(Level.FINE)) {
            return;
        }
        logger.logp(Level.FINE, componentClassName, getCallerMethodName(), message);
    
public voidfiner(java.lang.String message)

        if (!this.logger.isLoggable(Level.FINER)) {
            return;
        }
        logger.logp(Level.FINER, componentClassName, getCallerMethodName(), message);
    
public voidfiner(java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(Level.FINER)) {
            return;
        }
        logger.logp(Level.FINER, componentClassName, getCallerMethodName(), message, thrown);
    
public voidfinest(java.lang.String message)

        if (!this.logger.isLoggable(Level.FINEST)) {
            return;
        }
        logger.logp(Level.FINEST, componentClassName, getCallerMethodName(), message);
    
public voidfinest(java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(Level.FINEST)) {
            return;
        }
        logger.logp(Level.FINEST, componentClassName, getCallerMethodName(), message, thrown);
    
public static com.sun.xml.ws.policy.privateutil.PolicyLoggergetLogger(java.lang.Class componentClass)
The factory method returns preconfigured PolicyLogger wrapper for the class. Since there is no caching implemented, it is advised that the method is called only once per a class in order to initialize a final static logger variable, which is then used through the class to perform actual logging tasks.

param
componentClass class of the component that will use the logger instance. Must not be {@code null}.
return
logger instance preconfigured for use with the component
throws
NullPointerException if the componentClass parameter is {@code null}.

        return new PolicyLogger(componentClass.getName());
    
public voidinfo(java.lang.String message)

        if (!this.logger.isLoggable(Level.INFO)) {
            return;
        }
        logger.logp(Level.INFO, componentClassName, getCallerMethodName(), message);
    
public voidinfo(java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(Level.INFO)) {
            return;
        }
        logger.logp(Level.INFO, componentClassName, getCallerMethodName(), message, thrown);
    
public booleanisLoggable(java.util.logging.Level level)

        return this.logger.isLoggable(level);
    
public booleanisMethodCallLoggable()

        return this.logger.isLoggable(METHOD_CALL_LEVEL_VALUE);
    
public voidlog(java.util.logging.Level level, java.lang.String message)

        if (!this.logger.isLoggable(level)) {
            return;
        }
        logger.logp(level, componentClassName, getCallerMethodName(), message);
    
public voidlog(java.util.logging.Level level, java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(level)) {
            return;
        }
        logger.logp(level, componentClassName, getCallerMethodName(), message, thrown);
    
public TlogException(T exception, java.lang.Throwable cause, java.util.logging.Level level)
Method logs {@code exception}'s message at the logging level specified by the {@code level} argument.

If {@code cause} parameter is not {@code null}, it is logged as well and {@code exception} original cause is initialized with instance referenced by {@code cause} parameter.

param
exception exception whose message should be logged. Must not be {@code null}.
param
cause initial cause of the exception that should be logged as well and set as {@code exception}'s original cause. May be {@code null}.
param
level loging level which should be used for logging
return
the same exception instance that was passed in as the {@code exception} parameter.

        if (this.logger.isLoggable(level)) {
            if (cause == null) {
                logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage());
            } else {
                exception.initCause(cause);
                logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage(), cause);
            }
        }
        
        return exception;
    
public TlogException(T exception, boolean logCause, java.util.logging.Level level)
Method logs {@code exception}'s message at the logging level specified by the {@code level} argument.

If {@code logCause} parameter is {@code true}, {@code exception}'s original cause is logged as well (if exists). This may be used in cases when {@code exception}'s class provides constructor to initialize the original cause. In such case you do not need to use {@link #logException(Throwable, Throwable, Level) logException(exception, cause, level)} method version but you might still want to log the original cause as well.

param
exception exception whose message should be logged. Must not be {@code null}.
param
logCause deterimnes whether initial cause of the exception should be logged as well
param
level loging level which should be used for logging
return
the same exception instance that was passed in as the {@code exception} parameter.

        if (this.logger.isLoggable(level)) {
            if (logCause && exception.getCause() != null) {
                logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage(), exception.getCause());
            } else {
                logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage());
            }
        }
        
        return exception;
    
public TlogException(T exception, java.util.logging.Level level)
Same as {@link #logException(Throwable, Throwable, Level) logException(exception, true, level)}.

        if (this.logger.isLoggable(level)) {
            if (exception.getCause() == null) {
                logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage());
            } else {
                logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage(), exception.getCause());
            }
        }
        
        return exception;
    
public TlogSevereException(T exception, java.lang.Throwable cause)
Method logs {@code exception}'s message as a {@code SEVERE} logging level message.

If {@code cause} parameter is not {@code null}, it is logged as well and {@code exception} original cause is initialized with instance referenced by {@code cause} parameter.

param
exception exception whose message should be logged. Must not be {@code null}.
param
cause initial cause of the exception that should be logged as well and set as {@code exception}'s original cause. May be {@code null}.
return
the same exception instance that was passed in as the {@code exception} parameter.

        if (this.logger.isLoggable(Level.SEVERE)) {
            if (cause == null) {
                logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), exception.getMessage());
            } else {
                exception.initCause(cause);
                logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), exception.getMessage(), cause);
            }
        }
        
        return exception;
    
public TlogSevereException(T exception, boolean logCause)
Method logs {@code exception}'s message as a {@code SEVERE} logging level message.

If {@code logCause} parameter is {@code true}, {@code exception}'s original cause is logged as well (if exists). This may be used in cases when {@code exception}'s class provides constructor to initialize the original cause. In such case you do not need to use {@link #logSevereException(Throwable, Throwable)} method version but you might still want to log the original cause as well.

param
exception exception whose message should be logged. Must not be {@code null}.
param
logCause deterimnes whether initial cause of the exception should be logged as well
return
the same exception instance that was passed in as the {@code exception} parameter.

        if (this.logger.isLoggable(Level.SEVERE)) {
            if (logCause && exception.getCause() != null) {
                logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), exception.getMessage(), exception.getCause());
            } else {
                logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), exception.getMessage());
            }
        }
        
        return exception;
    
public TlogSevereException(T exception)
Same as {@link #logSevereException(Throwable, boolean) logSevereException(exception, true)}.

        if (this.logger.isLoggable(Level.SEVERE)) {
            if (exception.getCause() == null) {
                logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), exception.getMessage());
            } else {
                logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), exception.getMessage(), exception.getCause());
            }
        }
        
        return exception;
    
public voidsetLevel(java.util.logging.Level level)

        this.logger.setLevel(level);
    
public voidsevere(java.lang.String message)

        if (!this.logger.isLoggable(Level.SEVERE)) {
            return;
        }
        logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), message);
    
public voidsevere(java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(Level.SEVERE)) {
            return;
        }
        logger.logp(Level.SEVERE, componentClassName, getCallerMethodName(), message, thrown);
    
public voidwarning(java.lang.String message)

        if (!this.logger.isLoggable(Level.WARNING)) {
            return;
        }
        logger.logp(Level.WARNING, componentClassName, getCallerMethodName(), message);
    
public voidwarning(java.lang.String message, java.lang.Throwable thrown)

        if (!this.logger.isLoggable(Level.WARNING)) {
            return;
        }
        logger.logp(Level.WARNING, componentClassName, getCallerMethodName(), message, thrown);