public class Logger
extends java.lang.Object
# log4testng will log its own behavior (generally used for debugging this package only).
log4testng.debug=true
# Specifies the root Loggers logging level. Will log DEBUG level and above
log4testng.rootLogger=DEBUG
# The org.testng.reporters.EmailableReporter Logger will log TRACE level and above
log4testng.logger.org.testng.reporters.EmailableReporter=TRACE
# All Logger in packages below org.testng will log WARN level and above
log4testng.logger.org.testng=WARN
In your source files you will typically instantiate and use loggers this ways:
import org.testng.log4testng.Logger;
class ThisClass {
private static final Logger LOGGER = Logger.getLogger(ThisClass.class);
...
LOGGER.debug("entering myMethod()");
...
LOGGER.warn("unknown file: " + filename);
...
LOGGER.error("Unexpected error", exception);
Modifier and Type | Field and Description |
---|---|
private static boolean |
debug
Should log4testng log what it is doing (defaults to false).
|
private static int |
DEBUG |
private static java.lang.String |
DEBUG_PROPERTY
Debug property name in log4testng.properties.
|
private static java.io.PrintStream |
err
The standard error stream (this is allways System.err except for unit tests)
|
private static int |
ERROR |
private static int |
FATAL |
private static int |
i |
private static int |
INFO |
private static boolean |
initialized
true if the Logging system has been initialized.
|
private java.lang.Class |
klass
The logger's name.
|
private int |
level
The logger's level
|
private static int |
LEVEL_COUNT |
private static java.util.Map<java.lang.String,java.lang.Integer> |
levelMap
A map from level name to level integer index (TRACE->0, DEBUG->1 ...)
|
private static java.lang.String[] |
levelNames
An ordered list of level names.
|
private static java.lang.String |
LOGGER_PREFIX
Standard prefix of all logger names in log4testng.properties.
|
private static java.util.Map<java.lang.String,java.lang.Integer> |
loggerLevels
Map from Logger names to level index (as specified in log4testng.properties)
|
private static java.util.Map<java.lang.Class,Logger> |
loggers
Map of all known loggers.
|
private java.lang.String |
m_className |
private static java.io.PrintStream |
out
The standard output stream (this is allways System.out except for unit tests)
|
private static java.lang.String |
PREFIX
Standard prefix of all property names in log4testng.properties.
|
private static java.lang.String |
ROOT_LOGGER
Root logger name in log4testng.properties.
|
private static int |
rootLoggerLevel
The logging level of the root logger (defaults to warn).
|
private static int |
TRACE |
private static int |
WARN |
Modifier | Constructor and Description |
---|---|
private |
Logger(java.lang.Class pClass,
int pLevel) |
Modifier and Type | Method and Description |
---|---|
private static void |
checkProperties(java.util.Properties pProperties) |
void |
debug(java.lang.Object message)
Log a message object with the DEBUG level.
|
void |
debug(java.lang.Object message,
java.lang.Throwable t)
Log a message object with the DEBUG level including the stack trace of the Throwable t passed
as parameter.
|
void |
error(java.lang.Object message)
Log a message object with the ERROR level.
|
void |
error(java.lang.Object message,
java.lang.Throwable t)
Log a message object with the DEBUG level including the stack trace of the Throwable t passed
as parameter.
|
void |
fatal(java.lang.Object message)
Log a message object with the FATAL level.
|
void |
fatal(java.lang.Object message,
java.lang.Throwable t)
Log a message object with the FATAL level including the stack trace of the Throwable t passed
as parameter.
|
private static int |
getLevel(java.lang.Class pClass)
Returns the level associated to the current class.
|
static Logger |
getLogger(java.lang.Class pClass)
Retrieve a logger named according to the value of the pClass.getName() parameter.
|
void |
info(java.lang.Object message)
Log a message object with the INFO level.
|
void |
info(java.lang.Object message,
java.lang.Throwable t)
Log a message object with the WARN level including the stack trace of the Throwable t passed as
parameter.
|
private static void |
initialize() |
boolean |
isDebugEnabled()
Check whether this logger is enabled for the DEBUG Level.
|
boolean |
isInfoEnabled()
Check whether this logger is enabled for the INFO Level.
|
private boolean |
isLevelEnabled(int pLevel) |
boolean |
isTraceEnabled()
Check whether this logger is enabled for the TRACE Level.
|
private void |
log(int pLevel,
java.lang.Object pMessage,
java.lang.Throwable pT) |
private static void |
loglog4testng(java.lang.String pmessage)
Logs the message to System.out of debug is on.
|
static void |
main(java.lang.String[] pArgs)
Run all tests.
|
private static void |
testDebugDefault()
Makes sure the default debug value is false.
|
private static void |
testDebugError()
Makes sure an illegal debug value throws an exception.
|
private static void |
testDebugOff()
Makes sure the debug value can be turned off and logs nothing.
|
private static void |
testDebugOn()
Makes sure the debug value can be turned on and actualls logs something.
|
private static void |
testInitialize(java.util.Properties pProperties,
java.io.PrintStream pOut,
java.io.PrintStream pErr)
This method is for debugging purpose only.
|
private static void |
testRootLoggerDefault()
Tests that the root logger's default level is WARN and that loggers do not log bellow this
level and do log in the correct stream for levels equal to and above WARN.
|
private static void |
testRootLoggerSet()
Test setting the root logger level
|
private static void |
testRootLoggerSetError()
Test setting the root logger to an illegal level value throws an exception.
|
private static void |
testUserLoggerSet()
Test setting a user logger level
|
private static void |
testUserLoggerSetError()
Test setting a user logger to an illegal level value throws an exception
|
private static void |
testUserLoggerSetHierarchy()
Tests setting a partial logger name (a hierarchy scope)
|
void |
trace(java.lang.Object message)
Log a message object with the TRACE level.
|
void |
trace(java.lang.Object message,
java.lang.Throwable t)
Log a message object with the TRACE level including the stack trace of the Throwable t passed
as parameter.
|
void |
warn(java.lang.Object message)
Log a message object with the WARN level.
|
void |
warn(java.lang.Object message,
java.lang.Throwable t)
Log a message object with the ERROR level including the stack trace of the Throwable t passed
as parameter.
|
private static int i
private static final int TRACE
private static final int DEBUG
private static final int INFO
private static final int WARN
private static final int ERROR
private static final int FATAL
private static final int LEVEL_COUNT
private static final java.lang.String PREFIX
private static final java.lang.String LOGGER_PREFIX
private static final java.lang.String ROOT_LOGGER
private static final java.lang.String DEBUG_PROPERTY
private static java.io.PrintStream err
private static java.io.PrintStream out
private static final java.lang.String[] levelNames
private static final java.util.Map<java.lang.String,java.lang.Integer> levelMap
private static boolean initialized
private static final java.util.Map<java.lang.String,java.lang.Integer> loggerLevels
private static final java.util.Map<java.lang.Class,Logger> loggers
private static int rootLoggerLevel
private static boolean debug
private final int level
private final java.lang.Class klass
private final java.lang.String m_className
public static Logger getLogger(java.lang.Class pClass)
pClass
- The class' logger to retrieve.public boolean isTraceEnabled()
public void trace(java.lang.Object message)
message
- the message object to log.public void trace(java.lang.Object message, java.lang.Throwable t)
message
- the message object to log.t
- the exception to log, including its stack trace.public boolean isDebugEnabled()
public void debug(java.lang.Object message)
message
- the message object to log.public void debug(java.lang.Object message, java.lang.Throwable t)
message
- the message object to log.t
- the exception to log, including its stack trace.public boolean isInfoEnabled()
public void info(java.lang.Object message)
message
- the message object to log.public void info(java.lang.Object message, java.lang.Throwable t)
message
- the message object to log.t
- the exception to log, including its stack trace.public void warn(java.lang.Object message)
message
- the message object to log.public void warn(java.lang.Object message, java.lang.Throwable t)
message
- the message object to log.t
- the exception to log, including its stack trace.public void error(java.lang.Object message)
message
- the message object to log.public void error(java.lang.Object message, java.lang.Throwable t)
message
- the message object to log.t
- the exception to log, including its stack trace.public void fatal(java.lang.Object message)
message
- the message object to log.public void fatal(java.lang.Object message, java.lang.Throwable t)
message
- the message object to log.t
- the exception to log, including its stack trace.private static void initialize()
private static void checkProperties(java.util.Properties pProperties)
private static int getLevel(java.lang.Class pClass)
pClass
- the class name used for logger name.private boolean isLevelEnabled(int pLevel)
private void log(int pLevel, java.lang.Object pMessage, java.lang.Throwable pT)
private static void loglog4testng(java.lang.String pmessage)
pmessage
- the message to log to the consoleprivate static void testInitialize(java.util.Properties pProperties, java.io.PrintStream pOut, java.io.PrintStream pErr)
pProperties
- a properties bundle initialised as log4testng property file would be.pOut
- the standard output stream to be used for logging.pErr
- the standard error stream to be used for logging.private static void testDebugDefault()
private static void testDebugOn()
private static void testDebugOff()
private static void testDebugError()
private static void testRootLoggerDefault()
private static void testRootLoggerSet()
private static void testRootLoggerSetError()
private static void testUserLoggerSet()
private static void testUserLoggerSetError()
private static void testUserLoggerSetHierarchy()
public static void main(java.lang.String[] pArgs)
pArgs
- not used