FileDocCategorySizeDatePackage
ConsoleAppender.javaAPI DocApache log4j 1.2.155828Sat Aug 25 00:09:42 BST 2007org.apache.log4j

ConsoleAppender

public class ConsoleAppender extends WriterAppender
ConsoleAppender appends log events to System.out or System.err using a layout specified by the user. The default target is System.out.
author
Ceki Gülcü
author
Curt Arnold
since
1.1

Fields Summary
public static final String
SYSTEM_OUT
public static final String
SYSTEM_ERR
protected String
target
private boolean
follow
Determines if the appender honors reassignments of System.out or System.err made after configuration.
Constructors Summary
public ConsoleAppender()
Constructs an unconfigured appender.


          
    
  
public ConsoleAppender(Layout layout)
Creates a configured appender.

param
layout layout, may not be null.

    this(layout, SYSTEM_OUT);
  
public ConsoleAppender(Layout layout, String target)
Creates a configured appender.

param
layout layout, may not be null.
param
target target, either "System.err" or "System.out".

    setLayout(layout);
    setTarget(target);
    activateOptions();
  
Methods Summary
public voidactivateOptions()
Prepares the appender for use.

        if (follow) {
            if (target.equals(SYSTEM_ERR)) {
               setWriter(createWriter(new SystemErrStream()));
            } else {
               setWriter(createWriter(new SystemOutStream()));
            }
        } else {
            if (target.equals(SYSTEM_ERR)) {
               setWriter(createWriter(System.err));
            } else {
               setWriter(createWriter(System.out));
            }
        }

        super.activateOptions();
  
protected final voidcloseWriter()
{@inheritDoc}

     if (follow) {
        super.closeWriter();
     }
  
public final booleangetFollow()
Gets whether the appender honors reassignments of System.out or System.err made after configuration.

return
true if appender will use value of System.out or System.err in force at the time when logging events are appended.
since
1.2.13

      return follow;
  
public java.lang.StringgetTarget()
Returns the current value of the Target property. The default value of the option is "System.out". See also {@link #setTarget}.

    return target;
  
public final voidsetFollow(boolean newValue)
Sets whether the appender honors reassignments of System.out or System.err made after configuration.

param
newValue if true, appender will use value of System.out or System.err in force at the time when logging events are appended.
since
1.2.13

     follow = newValue;
  
public voidsetTarget(java.lang.String value)
Sets the value of the Target option. Recognized values are "System.out" and "System.err". Any other value will be ignored.

    String v = value.trim();

    if (SYSTEM_OUT.equalsIgnoreCase(v)) {
      target = SYSTEM_OUT;
    } else if (SYSTEM_ERR.equalsIgnoreCase(v)) {
      target = SYSTEM_ERR;
    } else {
      targetWarn(value);
    }
  
voidtargetWarn(java.lang.String val)

    LogLog.warn("["+val+"] should be System.out or System.err.");
    LogLog.warn("Using previously set target, System.out by default.");