Interface Logger
-
public interface Logger
SonarQube plugins are not coupled with external logging libraries like SLF4J or Logback.Example:
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 withFormatter
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.- Since:
- 5.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
debug(java.lang.String msg)
Logs a DEBUG message.void
debug(java.lang.String pattern, java.lang.Object arg)
Logs an DEBUG parameterized message according to the specified format and argument.void
debug(java.lang.String msg, java.lang.Object... args)
Logs an DEBUG parameterized message according to the specified format and arguments.void
debug(java.lang.String msg, java.lang.Object arg1, java.lang.Object arg2)
Logs an DEBUG parameterized message according to the specified format and arguments.default void
debug(java.util.function.Supplier<java.lang.String> msgSupplier)
Logs a DEBUG message which is only to be constructed if the logging level is such that the message will actually be logged.void
error(java.lang.String msg)
Logs an ERROR level message.void
error(java.lang.String msg, java.lang.Object arg)
Logs an ERROR parameterized message according to the specified format and argument.void
error(java.lang.String msg, java.lang.Object... args)
Logs a ERROR parameterized message according to the specified format and arguments.void
error(java.lang.String msg, java.lang.Object arg1, java.lang.Object arg2)
Logs a ERROR parameterized message according to the specified format and arguments.void
error(java.lang.String msg, java.lang.Throwable thrown)
Logs an exception at the ERROR level with an accompanying message.LoggerLevel
getLevel()
void
info(java.lang.String msg)
Logs an INFO level message.void
info(java.lang.String msg, java.lang.Object arg)
Logs an INFO parameterized message according to the specified format and argument.void
info(java.lang.String msg, java.lang.Object... args)
Logs an INFO parameterized message according to the specified format and arguments.void
info(java.lang.String msg, java.lang.Object arg1, java.lang.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(java.lang.String msg)
Logs a TRACE message.void
trace(java.lang.String pattern, java.lang.Object arg)
Logs an TRACE parameterized message according to the specified format and argument.void
trace(java.lang.String msg, java.lang.Object... args)
Logs an TRACE parameterized message according to the specified format and arguments.void
trace(java.lang.String msg, java.lang.Object arg1, java.lang.Object arg2)
Logs an TRACE parameterized message according to the specified format and arguments.default void
trace(java.util.function.Supplier<java.lang.String> msgSupplier)
Logs a TRACE message, which is only to be constructed if the logging level is such that the message will actually be logged.void
warn(java.lang.String msg)
Logs a WARN level message.void
warn(java.lang.String msg, java.lang.Object arg)
Logs a WARN parameterized message according to the specified format and argument.void
warn(java.lang.String msg, java.lang.Object... args)
Logs a WARN parameterized message according to the specified format and arguments.void
warn(java.lang.String msg, java.lang.Object arg1, java.lang.Object arg2)
Logs a WARN parameterized message according to the specified format and arguments.void
warn(java.lang.String msg, java.lang.Throwable throwable)
Logs an exception at the WARN level with an accompanying message.
-
-
-
Method Detail
-
isTraceEnabled
boolean isTraceEnabled()
-
trace
void trace(java.lang.String msg)
Logs a TRACE message.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.
-
trace
default void trace(java.util.function.Supplier<java.lang.String> msgSupplier)
Logs a TRACE message, which is only to be constructed if the logging level is such that the message will actually be logged.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.
- Parameters:
msgSupplier
- A function, which when called, produces the desired log message- Since:
- 6.3
-
trace
void trace(java.lang.String pattern, @Nullable java.lang.Object arg)
Logs an TRACE parameterized message according to the specified format and argument. Example: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.
-
trace
void trace(java.lang.String msg, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2)
Logs an TRACE parameterized message according to the specified format and arguments. Example: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.
-
trace
void trace(java.lang.String msg, java.lang.Object... args)
Logs an TRACE parameterized message according to the specified format and arguments. Example: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)
andtrace(String, Object, Object)
-
isDebugEnabled
boolean isDebugEnabled()
-
debug
void debug(java.lang.String msg)
Logs a DEBUG message.DEBUG messages must be valuable for diagnosing production problems. They must not be used for development debugging.
-
debug
default void debug(java.util.function.Supplier<java.lang.String> msgSupplier)
Logs a DEBUG message which is only to be constructed if the logging level is such that the message will actually be logged.DEBUG messages must be valuable for diagnosing production problems. They must not be used for development debugging.
- Parameters:
msgSupplier
- A function, which when called, produces the desired log message- Since:
- 6.3
-
debug
void debug(java.lang.String pattern, @Nullable java.lang.Object arg)
Logs an DEBUG parameterized message according to the specified format and argument. Example:debug("Value is {}", value)
Debug messages must be valuable for diagnosing production problems. They must not be used for development debugging.
-
debug
void debug(java.lang.String msg, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2)
Logs an DEBUG parameterized message according to the specified format and arguments. Example:debug("Values are {} and {}", value1, value2)
Debug messages must be valuable for diagnosing production problems. They must not be used for development debugging.
-
debug
void debug(java.lang.String msg, java.lang.Object... args)
Logs an DEBUG parameterized message according to the specified format and arguments. Example: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)
anddebug(String, Object, Object)
-
info
void info(java.lang.String msg)
Logs an INFO level message.
-
info
void info(java.lang.String msg, @Nullable java.lang.Object arg)
Logs an INFO parameterized message according to the specified format and argument. Example:info("Value is {}", value)
-
info
void info(java.lang.String msg, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2)
Logs an INFO parameterized message according to the specified format and arguments. Example:info("Values are {} and {}", value1, value2)
-
info
void info(java.lang.String msg, java.lang.Object... args)
Logs an INFO parameterized message according to the specified format and arguments. Example: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)
andinfo(String, Object, Object)
-
warn
void warn(java.lang.String msg)
Logs a WARN level message.
-
warn
void warn(java.lang.String msg, java.lang.Throwable throwable)
Logs an exception at the WARN level with an accompanying message.
-
warn
void warn(java.lang.String msg, @Nullable java.lang.Object arg)
Logs a WARN parameterized message according to the specified format and argument. Example:warn("Value is {}", value)
-
warn
void warn(java.lang.String msg, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2)
Logs a WARN parameterized message according to the specified format and arguments. Example:warn("Values are {} and {}", value1, value2)
-
warn
void warn(java.lang.String msg, java.lang.Object... args)
Logs a WARN parameterized message according to the specified format and arguments. Example: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)
andwarn(String, Object, Object)
-
error
void error(java.lang.String msg)
Logs an ERROR level message.
-
error
void error(java.lang.String msg, @Nullable java.lang.Object arg)
Logs an ERROR parameterized message according to the specified format and argument. Example:error("Value is {}", value)
-
error
void error(java.lang.String msg, @Nullable java.lang.Object arg1, @Nullable java.lang.Object arg2)
Logs a ERROR parameterized message according to the specified format and arguments. Example:error("Values are {} and {}", value1, value2)
-
error
void error(java.lang.String msg, java.lang.Object... args)
Logs a ERROR parameterized message according to the specified format and arguments. Example: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)
anderror(String, Object, Object)
-
error
void error(java.lang.String msg, java.lang.Throwable thrown)
Logs an exception at the ERROR level with an accompanying message.
-
setLevel
boolean setLevel(LoggerLevel level)
Attempt to change logger level. Return true if it succeeded, false if the underlying logging facility does not allow to change level at runtime.This method must not be used to enable DEBUG or TRACE logs in tests. Use
AbstractLogTester.setLevel(LoggerLevel)
instead.The standard use-case is to customize logging of embedded 3rd-party libraries.
-
getLevel
LoggerLevel getLevel()
-
-