Package com.log4rich.appenders
Class ConsoleAppender
java.lang.Object
com.log4rich.appenders.ConsoleAppender
- All Implemented Interfaces:
Appender
Appender that writes log events to console (stdout or stderr).
Thread-safe implementation using synchronized methods.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Target destination for console output. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new console appender that writes to STDOUT.Creates a new console appender that writes to the specified target. -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(LoggingEvent event) Appends a log event to the console output stream.void
close()
Closes this appender and releases any resources.Gets the current layout used for formatting log events.getLevel()
Gets the minimum log level for this appender.getName()
Gets the name of this appender.Gets the current target output stream for this appender.boolean
isClosed()
Checks if this appender is closed.boolean
isLevelEnabled
(LogLevel level) Checks if the specified log level is enabled for this appender.void
Sets the layout for formatting log events.void
Sets the minimum log level for this appender.void
Sets the name of this appender.void
setTarget
(ConsoleAppender.Target target) Sets the target output stream for this appender.
-
Constructor Details
-
ConsoleAppender
public ConsoleAppender()Creates a new console appender that writes to STDOUT. -
ConsoleAppender
Creates a new console appender that writes to the specified target.- Parameters:
target
- the target stream to write to
-
-
Method Details
-
append
Appends a log event to the console output stream. This method is thread-safe and handles formatting, output, and error recovery. -
setLayout
Sets the layout for formatting log events. -
getLayout
Gets the current layout used for formatting log events. -
setLevel
Sets the minimum log level for this appender. Only events at or above this level will be processed. -
getLevel
Gets the minimum log level for this appender. -
isLevelEnabled
Checks if the specified log level is enabled for this appender.- Specified by:
isLevelEnabled
in interfaceAppender
- 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. -
isClosed
public boolean isClosed()Checks if this appender is closed. -
setName
Sets the name of this appender. -
getName
Gets the name of this appender. -
setTarget
Sets the target output stream for this appender.- Parameters:
target
- the target stream to use, or null to use STDOUT
-
getTarget
Gets the current target output stream for this appender.- Returns:
- the current target stream
-