org.apache.commons.ssl

## Class LogWrapper

- java.lang.Object
- - org.apache.commons.ssl.LogWrapper

    public class LogWrapper
    extends java.lang.Object

LogWrapper can be used for situations where log4j might not be available on the classpath. It presents the most basic and critical components of the log4j API, and passes all log calls through to log4j if possible. If log4j is not available, logging is sent to standard-out by default.

This default logging to standard-out (which only occurs if log4j is NOT available) can be disabled or changed via the static setBackupStream() and setBackupLogFile() methods.

Since:
  3-Aug-2006
Author:
  Credit Union Central of British Columbia, www.cucbc.com, juliusdavies@cucbc.com

### Field Summary

Fields
`private static java.io.OutputStream` `backup` OutputStream to log to if log4j is not available.
`private static boolean` `DEBUG` Should we print DEBUG statements if log4j is not available?
`(package private) static java.text.DateFormat` `DF`
`private LogHelper` `h`
`(package private) static java.lang.String[]` `LEVELS`
`(package private) static java.lang.String` `LINE_SEPARATOR`
`static boolean` `log4j` true if log4j is available
`private static LogWrapper` `NOOP`
`(package private) static int` `TIMESTAMP_LENGTH`
`(package private) static java.lang.String` `TIMESTAMP_PATTERN`
`private static java.io.PrintStream` `wrappingPrintStream` The wrappingPrintStream is lazy-initted if we have to log a stacktrace.

### Constructor Summary

Constructors
`private` `LogWrapper()`
`private` `LogWrapper(java.lang.Class c)`
`private` `LogWrapper(java.lang.String s)`

### Method Summary

Methods
`void` `debug(java.lang.Object o)`
`void` `debug(java.lang.Object o, java.lang.Throwable t)`
`void` `error(java.lang.Object o)`
`void` `error(java.lang.Object o, java.lang.Throwable t)`
`void` `fatal(java.lang.Object o)`
`void` `fatal(java.lang.Object o, java.lang.Throwable t)`
`static java.io.OutputStream` `getBackupStream()` Get the PrintStream we're logging to if log4j is not available.
`java.lang.Object` `getLog4jLogger()`
`static LogWrapper` `getLogger(java.lang.Class c)`
`static LogWrapper` `getLogger(java.lang.String s)`
`void` `info(java.lang.Object o)`
`void` `info(java.lang.Object o, java.lang.Throwable t)`
`boolean` `isDebugEnabled()`
`boolean` `isInfoEnabled()`
`static boolean` `isLog4jAvailable()`
`static void` `setBackupLogFile(java.lang.String f)` Set file to log to if log4j is not available.
`static void` `setBackupStream(java.io.OutputStream os)` Set PrintStream to log to if log4j is not available.
`private boolean` `t(int level, java.lang.Object o, java.lang.Throwable t)` Tests if log4j is available.
`void` `warn(java.lang.Object o)`
`void` `warn(java.lang.Object o, java.lang.Throwable t)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### LEVELS

    static final java.lang.String[] LEVELS

#### TIMESTAMP_PATTERN

    static final java.lang.String TIMESTAMP_PATTERN

See Also:
  Constant Field Values

#### TIMESTAMP_LENGTH

    static final int TIMESTAMP_LENGTH

#### LINE_SEPARATOR

    static final java.lang.String LINE_SEPARATOR

#### DF

    static final java.text.DateFormat DF

#### NOOP

    private static final LogWrapper NOOP

#### DEBUG

    private static final boolean DEBUG

Should we print DEBUG statements if log4j is not available?

See Also:
  Constant Field Values

#### log4j

    public static final boolean log4j

true if log4j is available

#### backup

    private static volatile java.io.OutputStream backup

OutputStream to log to if log4j is not available. Set it to null to disable.

#### wrappingPrintStream

    private static volatile java.io.PrintStream wrappingPrintStream

The wrappingPrintStream is lazy-initted if we have to log a stacktrace.

#### h

    private final LogHelper h

### Constructor Detail

#### LogWrapper

    private LogWrapper()

#### LogWrapper

    private LogWrapper(java.lang.Class c)

#### LogWrapper

    private LogWrapper(java.lang.String s)

### Method Detail

#### isLog4jAvailable

    public static boolean isLog4jAvailable()

#### getLogger

    public static LogWrapper getLogger(java.lang.Class c)

#### getLogger

    public static LogWrapper getLogger(java.lang.String s)

#### debug

    public void debug(java.lang.Object o)

#### debug

    public void debug(java.lang.Object o,
             java.lang.Throwable t)

#### info

    public void info(java.lang.Object o)

#### info

    public void info(java.lang.Object o,
            java.lang.Throwable t)

#### warn

    public void warn(java.lang.Object o)

#### warn

    public void warn(java.lang.Object o,
            java.lang.Throwable t)

#### error

    public void error(java.lang.Object o)

#### error

    public void error(java.lang.Object o,
             java.lang.Throwable t)

#### fatal

    public void fatal(java.lang.Object o)

#### fatal

    public void fatal(java.lang.Object o,
             java.lang.Throwable t)

#### isDebugEnabled

    public boolean isDebugEnabled()

#### isInfoEnabled

    public boolean isInfoEnabled()

#### getLog4jLogger

    public java.lang.Object getLog4jLogger()

#### t

    private boolean t(int level,
            java.lang.Object o,
            java.lang.Throwable t)

Tests if log4j is available. If not, logs to backup OutputStream (if backup != null).

Parameters:
  `level` - log4j logging level for this statement
  `o` - object to log
  `t` - throwable to log
Returns:
  true if log4j is available, false if log4j is not. If it returns false, as a side-effect, it will also log the statement.

#### setBackupLogFile

    public static void setBackupLogFile(java.lang.String f)
                                 throws java.io.IOException

Set file to log to if log4j is not available.

Parameters:
  `f` - path to use for backup log file (if log4j not available)
Throws:
  `java.io.IOException` - if we can't write to the given path

#### setBackupStream

    public static void setBackupStream(java.io.OutputStream os)

Set PrintStream to log to if log4j is not available. Set to null to disable. Default value is System.out.

Parameters:
  `os` - outputstream to use for backup logging (if log4j not available)

#### getBackupStream

    public static java.io.OutputStream getBackupStream()

Get the PrintStream we're logging to if log4j is not available.

Returns:
  OutputStream we're using as our log4j replacement.