class LogUtils extends java.lang.Object
Utility methods for logging. Provides static methods to handle common logging tasks. Includes converting possibly long lists of domain objects to limited strings. Also has support for client side logging features.
Original Author: mphModifiers | Name | Description |
---|---|---|
static int |
MAX_ELEMENTS |
The maximum elements to be printed in the string representation of a list. |
static int |
MAX_ELEMENT_SIZE |
The maximum size of an element to be printed in the string representation of a list. |
Type | Name and description |
---|---|
private static java.util.Map<Level, groovy.lang.Range> |
clientLevelMap Maps the client logging framework's level number ranges with the server-side levels. |
private static boolean |
disableStackTraceLogging If true, then the stack trace logging is disabled. |
Constructor and description |
---|
LogUtils
() |
Type Params | Return Type | Name and description |
---|---|---|
|
static ch.qos.logback.classic.Level |
convertClientLevelToServerLevel(java.lang.Integer clientLevel) Converts a client-side trace level number to a server-side trace level. |
|
static java.lang.Integer |
convertLevelToClientLogSetting(ch.qos.logback.classic.Level level) Converts a server-side trace level to a client-side trace level number. |
|
static java.lang.String |
convertPageToClientLoggerName(java.lang.String page) Converts a page URI to a server-side logger name for use with client-side logging. |
|
static java.lang.String |
extractImportantMethodsFromStackTrace() |
|
static org.slf4j.Logger |
getLogger(java.lang.String loggerID) Finds the logger for the given logging ID (e.g. package/class name). |
|
static org.slf4j.Logger |
getLogger(java.lang.Class clazz) Finds the logger for the given class. |
|
static java.lang.String |
limitedLengthList(java.util.List list) Build a string representation of the list of objects with limits on the size of each object and number of objects. |
|
static java.lang.String |
limitedLengthString(java.lang.String s) Trims the given string if it exceeds the MAX_ELEMENT_SIZE (40). |
|
static java.lang.String |
limitedLengthString(java.lang.String s, int maxLength) Trims the given string if it exceeds the MAX_ELEMENT_SIZE (default: 40). |
|
static void |
logClientMessage(java.util.Map json, java.util.Map params) Logs the given client-side message to the standard logger. |
|
static void |
logStackTrace(org.slf4j.Logger logger, java.lang.Throwable e, java.lang.Object source) Logs a given stack trace for safety. |
|
static java.lang.Object |
toLevel(java.lang.String level) Converts the given string Level to the correct logger Level. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
The maximum elements to be printed in the string representation of a list. (Value: 20)
The maximum size of an element to be printed in the string representation of a list. (Value: 40)
Maps the client logging framework's level number ranges with the server-side levels.
If true, then the stack trace logging is disabled. Only use for unit testing.
Converts a client-side trace level number to a server-side trace level. (e.g. 2000 -> Level.DEBUG). If a client level is not found, then the next lowest value is returned.
level
- The client-side level number.Converts a server-side trace level to a client-side trace level number. (e.g. Level.ERROR -> 5000).
level
- The server-side level.Converts a page URI to a server-side logger name for use with client-side logging. For example, converts '/order/show' to 'client.order.show'.
page
- The URI of the page to convert to a logger name.Finds the logger for the given logging ID (e.g. package/class name).
loggerID
- The logger ID (full class name).Finds the logger for the given class.
clazz
- The class.Build a string representation of the list of objects with limits on the size of each object and number of objects. If the string or count exceeds the limits, place holders are printed (... and '10 more...').
list
- The list of objects to print strings for.Trims the given string if it exceeds the MAX_ELEMENT_SIZE (40).
s
- The string to (maybe) trim.Trims the given string if it exceeds the MAX_ELEMENT_SIZE (default: 40).
s
- The string to (maybe) trim.maxLength
- The max length.Logs the given client-side message to the standard logger. The input JSON is provided by the client logging framework.
json
- The content of the logging request from the client framework. This contains an array ('lg') or maps.
The maps contain two important elements: 'l' (level as int), 'm' (the message text).params
- The HTTP request parameters (uses 'logger' as the name of the server-side logger).Logs a given stack trace for safety. Does not log BusinessException since those are mostly expected exceptions.
logger
- The logger to use.e
- The exception.source
- The source (optional). Logged with the message.Converts the given string Level to the correct logger Level.
level
- The level string to convert.Groovy Documentation