Class ConsoleAppender

java.lang.Object
com.log4rich.appenders.ConsoleAppender
All Implemented Interfaces:
Appender

public class ConsoleAppender extends Object implements Appender
Appender that writes log events to console (stdout or stderr). Thread-safe implementation using synchronized methods.
  • Constructor Details

    • ConsoleAppender

      public ConsoleAppender()
      Creates a new console appender that writes to STDOUT.
    • ConsoleAppender

      public ConsoleAppender(ConsoleAppender.Target target)
      Creates a new console appender that writes to the specified target.
      Parameters:
      target - the target stream to write to
  • Method Details

    • append

      public void append(LoggingEvent event)
      Appends a log event to the console output stream. This method is thread-safe and handles formatting, output, and error recovery.
      Specified by:
      append in interface Appender
      Parameters:
      event - the logging event to append
    • setLayout

      public void setLayout(Layout layout)
      Sets the layout for formatting log events.
      Specified by:
      setLayout in interface Appender
      Parameters:
      layout - the layout to use, or null to use the default StandardLayout
    • getLayout

      public Layout getLayout()
      Gets the current layout used for formatting log events.
      Specified by:
      getLayout in interface Appender
      Returns:
      the current layout
    • setLevel

      public void setLevel(LogLevel level)
      Sets the minimum log level for this appender. Only events at or above this level will be processed.
      Specified by:
      setLevel in interface Appender
      Parameters:
      level - the minimum log level, or null to use TRACE (accept all)
    • getLevel

      public LogLevel getLevel()
      Gets the minimum log level for this appender.
      Specified by:
      getLevel in interface Appender
      Returns:
      the minimum log level
    • isLevelEnabled

      public boolean isLevelEnabled(LogLevel level)
      Checks if the specified log level is enabled for this appender.
      Specified by:
      isLevelEnabled in interface Appender
      Parameters:
      level - the log level to check
      Returns:
      true if the level is enabled, false otherwise
    • close

      public void close()
      Closes this appender and releases any resources. Note: System.out and System.err are not closed as they are shared resources.
      Specified by:
      close in interface Appender
    • isClosed

      public boolean isClosed()
      Checks if this appender is closed.
      Specified by:
      isClosed in interface Appender
      Returns:
      true if the appender is closed, false otherwise
    • setName

      public void setName(String name)
      Sets the name of this appender.
      Specified by:
      setName in interface Appender
      Parameters:
      name - the name to set, or null to use the default "Console"
    • getName

      public String getName()
      Gets the name of this appender.
      Specified by:
      getName in interface Appender
      Returns:
      the appender name
    • setTarget

      public void setTarget(ConsoleAppender.Target target)
      Sets the target output stream for this appender.
      Parameters:
      target - the target stream to use, or null to use STDOUT
    • getTarget

      public ConsoleAppender.Target getTarget()
      Gets the current target output stream for this appender.
      Returns:
      the current target stream