public interface LogService extends Service
Debug Log messages can be static Strings or constructed with a template. It is best practice to use
message templates over String concatenation because templates are more efficient and produce neater, easier to read
code. Strings for message templates are only constructed if logging is enabled, whereas String concatenation must be
wrapped in an if
statement to check enablement.
For example:
logService.info("Exceeded the {} limit of {}.", limitType, count);
Is equivalent to:
if (log.isDebugEnabled()) {
logService.info("Exceeded the " + limitType + " limit of " + count + ".");
}
You can choose between the DEBUG, INFO, and ERROR types to categorize your log messages.
isDebugEnabled()
, isInfoEnabled()
, and isErrorEnabled()
either all return
true
or all return false
.
Modifier and Type | Method and Description |
---|---|
void |
debug(String message)
Outputs a DEBUG type message to the Debug Log.
|
void |
debug(String messageTemplate,
Object... args)
Outputs the templated DEBUG type message to the Debug Log.
|
void |
debug(Supplier<String> messageSupplier)
Output the String returned from a single call to messageSupplier.get() to the Debug Log.
|
void |
error(String message)
Outputs an ERROR type message to the Debug Log.
|
void |
error(String messageTemplate,
Object... args)
Outputs the templated ERROR type message to the Debug Log.
|
void |
error(Supplier<String> messageSupplier)
Output the String returned from a single call to messageSupplier.get() to the Debug Log.
|
void |
info(String message)
Outputs an INFO type message to the Debug Log.
|
void |
info(String messageTemplate,
Object... args)
Outputs the templated INFO type message to the Debug Log.
|
void |
info(Supplier<String> messageSupplier)
Output the String returned from a single call to messageSupplier.get() to the Debug Log.
|
boolean |
isDebugEnabled()
Checks if the Debug Log is enabled.
|
boolean |
isErrorEnabled()
Checks if the Debug Log is enabled.
|
boolean |
isInfoEnabled()
Checks if the Debug Log is enabled.
|
void |
logResourceUsage(String message)
Outputs current resource usage for elapsed time (milliseconds), memory (bytes), and CPU time (nanoseconds)
to the Debug Log.
|
boolean isDebugEnabled()
boolean isInfoEnabled()
boolean isErrorEnabled()
void debug(String message)
message
- message to outputvoid info(String message)
message
- message to outputvoid error(String message)
message
- message to outputvoid logResourceUsage(String message)
Outputs current resource usage for elapsed time (milliseconds), memory (bytes), and CPU time (nanoseconds) to the Debug Log.
For example:
"message": elapsed(ms)=35 memory(b)=25744 CPU(ns)=28831998
message
- message to output in addition to resource usagevoid debug(String messageTemplate, Object... args)
Outputs the templated DEBUG type message to the Debug Log.
The messageTemplate
may contain the template variable {}
. The number of template
variables must match the number of arguments passed to the method. Arguments are converted to Strings
with toString()
for Object arguments and String.valueOf(_)
for primitive arguments.
Instances of {}
in the message template are replaced, in order, with the converted String values of
the arguments.
For example:
logService.debug("The {} limit of {} has been reached.", limitType, count);
messageTemplate
- message templateargs
- arguments to replace the {} variables in the templatevoid info(String messageTemplate, Object... args)
Outputs the templated INFO type message to the Debug Log.
The messageTemplate
may contain the template variable {}
. The number of template
variables must match the number of arguments passed to the method. Arguments are converted to Strings
with toString()
for Object arguments and String.valueOf(_)
for primitive arguments.
Instances of {}
in the message template are replaced, in order, with the converted String value
of the arguments.
For example:
logService.debug("The {} limit of {} has been reached.", limitType, count);
messageTemplate
- message templateargs
- arguments to replace the {} variables in the templatevoid error(String messageTemplate, Object... args)
Outputs the templated ERROR type message to the Debug Log.
The messageTemplate
may contain the template variable {}
. The number of template
variables must match the number of arguments passed to the method. Arguments are converted to Strings
with toString()
for Object arguments and String.valueOf(_)
for primitive arguments.
Instances of {}
in the message template are replaced, in order, with the converted String values of
the arguments.
For example:
logService.debug("The {} limit of {} has been reached.", limitType, count);
messageTemplate
- message templateargs
- arguments to replace the {} variables in the templatevoid debug(Supplier<String> messageSupplier)
messageSupplier
- supplier providing a message to outputvoid info(Supplier<String> messageSupplier)
messageSupplier
- supplier providing a message to outputCopyright © Veeva Systems 2017–2019. All rights reserved.