public interface Logger
public class MyClass { private static final Logger LOGGER = Loggers.get("logger_name"); public void doSomething() { LOGGER.info("something valuable for production environment"); LOGGER.warn("message with arguments {} and {}", "foo", 42); } }Message arguments are defined with
{}
, but not with Formatter
syntax.
INFO, WARN and ERROR levels are always enabled. They can't be disabled by users.
DEBUG and TRACE levels are enabled on demand with the property sonar.log.level
.
See LogTester
for testing facilities.Modifier and Type | Method and Description |
---|---|
void |
debug(String msg)
Logs a DEBUG message.
|
void |
debug(String msg,
Object... args)
Logs an DEBUG parameterized message according to the specified format and arguments.
|
void |
debug(String pattern,
Object arg)
Logs an DEBUG parameterized message according to the specified format and argument.
|
void |
debug(String msg,
Object arg1,
Object arg2)
Logs an DEBUG parameterized message according to the specified format and arguments.
|
void |
error(String msg)
Logs an ERROR level message.
|
void |
error(String msg,
Object... args)
Logs a ERROR parameterized message according to the specified format and arguments.
|
void |
error(String msg,
Object arg)
Logs an ERROR parameterized message according to the specified format and argument.
|
void |
error(String msg,
Object arg1,
Object arg2)
Logs a ERROR parameterized message according to the specified format and arguments.
|
void |
error(String msg,
Throwable thrown)
Logs an exception at the ERROR level with an accompanying message.
|
LoggerLevel |
getLevel() |
void |
info(String msg)
Logs an INFO level message.
|
void |
info(String msg,
Object... args)
Logs an INFO parameterized message according to the specified format and arguments.
|
void |
info(String msg,
Object arg)
Logs an INFO parameterized message according to the specified format and argument.
|
void |
info(String msg,
Object arg1,
Object arg2)
Logs an INFO parameterized message according to the specified format and arguments.
|
boolean |
isDebugEnabled() |
boolean |
isTraceEnabled() |
boolean |
setLevel(LoggerLevel level)
Attempt to change logger level.
|
void |
trace(String msg)
Logs a TRACE message.
|
void |
trace(String msg,
Object... args)
Logs an TRACE parameterized message according to the specified format and arguments.
|
void |
trace(String pattern,
Object arg)
Logs an TRACE parameterized message according to the specified format and argument.
|
void |
trace(String msg,
Object arg1,
Object arg2)
Logs an TRACE parameterized message according to the specified format and arguments.
|
void |
warn(String msg)
Logs a WARN level message.
|
void |
warn(String msg,
Object... args)
Logs a WARN parameterized message according to the specified format and arguments.
|
void |
warn(String msg,
Object arg)
Logs a WARN parameterized message according to the specified format and argument.
|
void |
warn(String msg,
Object arg1,
Object arg2)
Logs a WARN parameterized message according to the specified format and arguments.
|
void |
warn(String msg,
Throwable throwable)
Logs an exception at the WARN level with an accompanying message.
|
boolean isTraceEnabled()
void trace(String msg)
void trace(String pattern, @Nullable Object arg)
trace("Value is {}", value)
TRACE messages must
be valuable for diagnosing production problems. They must not be used for development debugging.
They can significantly slow down performances. The standard use-case is logging of
SQL and Elasticsearch requests.void trace(String msg, @Nullable Object arg1, @Nullable Object arg2)
trace("Values are {} and {}", value1, value2)
TRACE messages must
be valuable for diagnosing production problems. They must not be used for development debugging.
They can significantly slow down performances. The standard use-case is logging of
SQL and Elasticsearch requests.void trace(String msg, Object... args)
trace("Values are {} and {}", value1, value2)
TRACE messages must
be valuable for diagnosing production problems. They must not be used for development debugging.
They can significantly slow down performances. The standard use-case is logging of
SQL and Elasticsearch requests.
This variant incurs the hidden cost of creating an Object[] before invoking the method.
The variants taking one and two arguments exist solely in order to avoid this hidden cost. See
trace(String, Object)
and trace(String, Object, Object)
boolean isDebugEnabled()
void debug(String msg)
void debug(String pattern, @Nullable Object arg)
debug("Value is {}", value)
Debug messages must
be valuable for diagnosing production problems. They must not be used for development debugging.void debug(String msg, @Nullable Object arg1, @Nullable Object arg2)
debug("Values are {} and {}", value1, value2)
Debug messages must
be valuable for diagnosing production problems. They must not be used for development debugging.void debug(String msg, Object... args)
debug("Values are {}, {} and {}", value1, value2, value3)
Debug messages must
be valuable for diagnosing production problems. They must not be used for development debugging.
*
This variant incurs the hidden cost of creating an Object[] before invoking the method.
The variants taking one and two arguments exist solely in order to avoid this hidden cost. See
debug(String, Object)
and debug(String, Object, Object)
void info(String msg, @Nullable Object arg)
info("Value is {}", value)
void info(String msg, @Nullable Object arg1, @Nullable Object arg2)
info("Values are {} and {}", value1, value2)
void info(String msg, Object... args)
info("Values are {}, {} and {}", value1, value2, value3)
This variant incurs the hidden cost of creating an Object[] before invoking the method.
The variants taking one and two arguments exist solely in order to avoid this hidden cost. See
info(String, Object)
and info(String, Object, Object)
void warn(String msg, Throwable throwable)
void warn(String msg, @Nullable Object arg)
warn("Value is {}", value)
void warn(String msg, @Nullable Object arg1, @Nullable Object arg2)
warn("Values are {} and {}", value1, value2)
void warn(String msg, Object... args)
warn("Values are {}, {} and {}", value1, value2, value3)
This variant incurs the hidden cost of creating an Object[] before invoking the method.
The variants taking one and two arguments exist solely in order to avoid this hidden cost. See
warn(String, Object)
and warn(String, Object, Object)
void error(String msg, @Nullable Object arg)
error("Value is {}", value)
void error(String msg, @Nullable Object arg1, @Nullable Object arg2)
error("Values are {} and {}", value1, value2)
void error(String msg, Object... args)
error("Values are {}, {} and {}", value1, value2, value3)
This variant incurs the hidden cost of creating an Object[] before invoking the method.
The variants taking one and two arguments exist solely in order to avoid this hidden cost. See
error(String, Object)
and error(String, Object, Object)
void error(String msg, Throwable thrown)
boolean setLevel(LoggerLevel level)
LogTester.setLevel(LoggerLevel)
instead.
The standard use-case is to customize logging of embedded 3rd-party
libraries.LoggerLevel getLevel()
Copyright © 2009–2016 SonarSource. All rights reserved.