- java.lang.Object
-
- nl.altindag.log.LogCaptor
-
- All Implemented Interfaces:
AutoCloseable
public final class LogCaptor extends Object implements AutoCloseable
- Author:
- Hakan Altindag
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFilter(ch.qos.logback.core.filter.Filter<ch.qos.logback.classic.spi.ILoggingEvent> filter)voidclearLogs()voidclose()voiddisableConsoleOutput()Disables the output of the log entries to the console.voiddisableLogs()Overrides the log level property of the target logger.voidenableConsoleOutput()The output of the log entries to the console are enabled by default but can be re-enabled if they are disabled earlier bydisableConsoleOutput()static LogCaptorforClass(Class<?> clazz)Captures log messages for the provided classstatic LogCaptorforName(String name)Captures log messages for the provided logger namestatic LogCaptorforRoot()Captures all log messagesList<String>getDebugLogs()List<String>getErrorLogs()List<String>getInfoLogs()List<LogEvent>getLogEvents()List<String>getLogs()List<String>getTraceLogs()List<String>getWarnLogs()booleanhasDebugMessage(String message)booleanhasErrorMessage(String message)booleanhasInfoMessage(String message)booleanhasMessage(String message)booleanhasTraceMessage(String message)booleanhasWarnMessage(String message)voidresetLogLevel()Resets the log level of the target logger to the initial value which was available before changing it withsetLogLevelToInfo(),setLogLevelToDebug()or withsetLogLevelToTrace()voidsetLogLevelToDebug()Overrides the log level property of the target logger.voidsetLogLevelToInfo()Overrides the log level property of the target logger.voidsetLogLevelToTrace()Overrides the log level property of the target logger.StringtoString()
-
-
-
Method Detail
-
forRoot
public static LogCaptor forRoot()
Captures all log messages- Returns:
- LogCaptor instance for the root logger
-
forClass
public static LogCaptor forClass(Class<?> clazz)
Captures log messages for the provided class- Parameters:
clazz- Class for capturing- Returns:
- LogCaptor instance for the provided class
-
forName
public static LogCaptor forName(String name)
Captures log messages for the provided logger name- Parameters:
name- Logger name for capturing- Returns:
- LogCaptor instance for the provided logger name
-
hasMessage
public boolean hasMessage(String message)
-
hasInfoMessage
public boolean hasInfoMessage(String message)
-
hasDebugMessage
public boolean hasDebugMessage(String message)
-
hasWarnMessage
public boolean hasWarnMessage(String message)
-
hasErrorMessage
public boolean hasErrorMessage(String message)
-
hasTraceMessage
public boolean hasTraceMessage(String message)
-
addFilter
public void addFilter(ch.qos.logback.core.filter.Filter<ch.qos.logback.classic.spi.ILoggingEvent> filter)
-
setLogLevelToInfo
public void setLogLevelToInfo()
Overrides the log level property of the target logger. This may result that the overridden property of the target logger is still active even though a new instance ofLogCaptorhas been created. To roll-back to the initial state use:resetLogLevel()This option will implicitly include the following log levels: WARN and ERROR
-
setLogLevelToDebug
public void setLogLevelToDebug()
Overrides the log level property of the target logger. This may result that the overridden property of the target logger is still active even though a new instance ofLogCaptorhas been created. To roll-back to the initial state use:resetLogLevel()This option will implicitly include the following log levels: INFO, WARN and ERROR
-
setLogLevelToTrace
public void setLogLevelToTrace()
Overrides the log level property of the target logger. This may result that the overridden property of the target logger is still active even though a new instance ofLogCaptorhas been created. To roll-back to the initial state use:resetLogLevel()This option will implicitly include the following log levels: INFO, DEBUG, WARN and ERROR
-
disableLogs
public void disableLogs()
Overrides the log level property of the target logger. This may result that the overridden property of the target logger is still active even though a new instance ofLogCaptorhas been created. To roll-back to the initial state use:resetLogLevel()
-
disableConsoleOutput
public void disableConsoleOutput()
Disables the output of the log entries to the console. To revert this option useenableConsoleOutput(). LogCaptor will still be capturing the log entries.
-
enableConsoleOutput
public void enableConsoleOutput()
The output of the log entries to the console are enabled by default but can be re-enabled if they are disabled earlier bydisableConsoleOutput()
-
resetLogLevel
public void resetLogLevel()
Resets the log level of the target logger to the initial value which was available before changing it withsetLogLevelToInfo(),setLogLevelToDebug()or withsetLogLevelToTrace()
-
clearLogs
public void clearLogs()
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-