Class LoggerMethods
Contains one-liners for logging operations.
The one-liners in this class make it easy to log INFO, WARNING, ALERT, TRACE, and DEBUG-level messages to Martini's underlying logging engine. The default logger used by these one-liners is named Martini.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFishTag(String key, String value) Fish tagging is a technique in log4j wherein log statements are stamped with unique tags / information to allow for easier log tracing.static voidClears all previously added fish tags.static StringLogs a DEBUG message to the underlying log engine of Martini, using a logger named Martini.static StringLogs a DEBUG message to the underlying log engine of Martini, using a logger named afterloggerName.static StringdebugIfEnabled(String message) Logs a DEBUG message to the underlying log engine of Martini, using a logger named Martini.static StringdebugIfEnabled(String loggerName, String message) Logs a DEBUG message to the underlying log engine of Martini, using a logger named afterloggerName.static StringLogs an ERROR message to the underlying log engine of Martini, using a logger named Martini.static StringLogs an ERROR message to the underlying log engine of Martini, using a logger named afterloggerName.static StringLogs an ERROR message to the underlying log engine of Martini, using a logger named afterloggerName.static StringLogs an ERROR message to the underlying log engine of Martini, using a logger named Martini.static StringerrorIfEnabled(String message) Logs an ERROR message to the underlying log engine of Martini, using a logger named Martini.static StringerrorIfEnabled(String loggerName, String message) Logs an ERROR message to the underlying log engine of Martini, using a logger named afterloggerName.static StringerrorIfEnabled(String loggerName, String message, Throwable throwable) Logs an ERROR message to the underlying log engine of Martini, using a logger named afterloggerName.static StringerrorIfEnabled(String message, Throwable throwable) Logs an ERROR message to the underlying log engine of Martini, using a logger named Martini.static StringLogs an INFO message to the underlying log engine of Martini, using a logger named Martini.static StringLogs an INFO message to the underlying log engine of Martini, using a logger named afterloggerName.static StringinfoIfEnabled(String message) Logs a INFO message to the underlying log engine of Martini, using a logger named Martini.static StringinfoIfEnabled(String loggerName, String message) Logs an INFO message to the underlying log engine of Martini, using a logger named afterloggerName.logger()Get a logged named groovy.static ApplicationLoggerGet a logger named after a class.static ApplicationLoggerGet a logger named after a script.static StringLog a message using a logger named afterscriptName.static StringPrint a message using}.invalid @link
{@link System#out#print(String)static StringPrint a message using}.invalid @link
{@link System#out#println(String)static voidremoveFishTag(String key) Removes the fish tag denoted by the key specifiedstatic StringLogs a TRACE message to the underlying log engine of Martini, using a logger named Martini.static StringLogs a TRACE message to the underlying log engine of Martini, using a logger named afterloggerName.static StringtraceIfEnabled(String message) Logs a TRACE message to the underlying log engine of Martini, using a logger named Martini.static StringtraceIfEnabled(String loggerName, String message) Logs a TRACE message to the underlying log engine of Martini, using a logger named afterloggerName.static StringLogs a WARN message to the underlying log engine of Martini, using a logger named Martini.static StringLogs a WARN message to the underlying log engine of Martini, using a logger named afterloggerName.static StringwarnIfEnabled(String message) Logs a WARN message to the underlying log engine of Martini, using a logger named Martini.static StringwarnIfEnabled(String loggerName, String message) Logs a WARN message to the underlying log engine of Martini, using a logger named afterloggerName.
-
Field Details
-
CONTEXT_MAP
-
-
Constructor Details
-
LoggerMethods
LoggerMethods()
-
-
Method Details
-
print
Print a message using}.invalid @link
{@link System#out#print(String)- Parameters:
message- the message- Returns:
- the printed message
- Since:
- 1.0
-
println
Print a message using}.invalid @link
{@link System#out#println(String)- Parameters:
message- the message- Returns:
- the printed message
- Since:
- 1.0
-
logger
Get a logger named after a script. The logger can then be used by a script to log to Martini's underlying logging engine.
Example usage:
def logger = 'tld.organization.project.Script'.logger() logger.info( "This message will be logged at the INFO level" );
- Parameters:
scriptName- the name of the logger- Returns:
- the
logger - Since:
- 1.0
-
logger
Get a logger named after a class. The logger can then be used by a script to log to Martini's underlying logging engine.
Example usage:
def logger = getClass().logger() logger.info( "This message will be logged at the INFO level" );
- Parameters:
clazz- the class to attach the logger to- Returns:
- the
logger - Since:
- 1.0
-
logger
Get a logged named groovy. The logger can then be used by a script to log to Martini's underlying logging engine.
Example usage:
def logger = logger() logger.info( "This message will be logged at the INFO level" );
- Returns:
- the
logger - Since:
- 1.0
-
logTo
Log a message using a logger named after
scriptName.Example usage:
'This message will be logged at the INFO level'.logTo( 'tld.organization.project.Script' )
- Parameters:
message- the message to logscriptName- the name of the logger- Returns:
- the message to log
- Since:
- 1.0
-
trace
Logs a TRACE message to the underlying log engine of Martini, using a logger named Martini.
Example usage:
'This message will be logged at the TRACE level'.trace();
- Parameters:
message- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
trace
Logs a TRACE message to the underlying log engine of Martini, using a logger named after
loggerName.Example usage:
'tld.organization.project.Script'.trace( 'This message will be logged at the TRACE level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
traceIfEnabled
Logs a TRACE message to the underlying log engine of Martini, using a logger named Martini. To succeed, TRACE messages must be enabled for said logger.
Example usage:
'This message will be logged at the TRACE level'.traceIfEnabled();
- Returns:
- the message to log
- Since:
- 1.0
-
traceIfEnabled
public static String traceIfEnabled(@GloopParameter(allowNull=false) String loggerName, String message) Logs a TRACE message to the underlying log engine of Martini, using a logger named after
loggerName. To succeed, TRACE messages must be enabled for said logger.Example usage:
'tld.organization.project.Script'.traceIfEnabled( 'This message will be logged at the TRACE level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
debug
Logs a DEBUG message to the underlying log engine of Martini, using a logger named Martini.
Example usage:
'This message will be logged at the DEBUG level'.debug();
- Returns:
- the message to log
- Since:
- 1.0
-
debug
Logs a DEBUG message to the underlying log engine of Martini, using a logger named after
loggerName.Example usage:
'tld.organization.project.Script'.debug( 'This message will be logged at the DEBUG level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
debugIfEnabled
Logs a DEBUG message to the underlying log engine of Martini, using a logger named Martini. To succeed, DEBUG messages must be enabled for said logger.
Example usage:
'This message will be logged at the DEBUG level'.debugIfEnabled();
- Returns:
- the message to log
- Since:
- 1.0
-
debugIfEnabled
public static String debugIfEnabled(@GloopParameter(allowNull=false) String loggerName, String message) Logs a DEBUG message to the underlying log engine of Martini, using a logger named after
loggerName. To succeed, DEBUG messages must be enabled for said logger.Example usage:
'tld.organization.project.Script'.debugIfEnabled( 'This message will be logged at the DEBUG level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
info
Logs an INFO message to the underlying log engine of Martini, using a logger named Martini.
Example usage:
'This message will be logged at the INFO level'.info();
- Parameters:
message- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
info
Logs an INFO message to the underlying log engine of Martini, using a logger named after
loggerName.Example usage:
'tld.organization.project.Script'.info( 'This message will be logged at the INFO level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
infoIfEnabled
Logs a INFO message to the underlying log engine of Martini, using a logger named Martini. To succeed, INFO messages must be enabled for said logger.
Example usage:
'This message will be logged at the INFO level'.infoIfEnabled();
- Parameters:
message- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
infoIfEnabled
public static String infoIfEnabled(@GloopParameter(allowNull=false) String loggerName, String message) Logs an INFO message to the underlying log engine of Martini, using a logger named after
loggerName. To succeed, INFO messages must be enabled for said logger.Example usage:
'tld.organization.project.Script'.infoIfEnabled( 'This message will be logged at the INFO level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
warn
Logs a WARN message to the underlying log engine of Martini, using a logger named Martini.
Example usage:
'This message will be logged at the WARN level'.warn();
- Parameters:
message- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
warn
Logs a WARN message to the underlying log engine of Martini, using a logger named after
loggerName.Example usage:
'tld.organization.project.Script'.warn( 'This message will be logged at the WARN level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
warnIfEnabled
Logs a WARN message to the underlying log engine of Martini, using a logger named Martini. To succeed, WARN messages must be enabled for said logger.
Example usage:
'This message will be logged at the WARN level'.warnIfEnabled();
- Parameters:
message- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
warnIfEnabled
public static String warnIfEnabled(@GloopParameter(allowNull=false) String loggerName, String message) Logs a WARN message to the underlying log engine of Martini, using a logger named after
loggerName. To succeed, WARN messages must be enabled for said logger.Example usage:
'tld.organization.project.Script'.warnIfEnabled( 'This message will be logged at the WARN level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
error
Logs an ERROR message to the underlying log engine of Martini, using a logger named Martini.
Example usage:
'This message will be logged at the ERROR level'.error();
- Parameters:
message- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
error
Logs an ERROR message to the underlying log engine of Martini, using a logger named after
loggerName.Example usage:
'tld.organization.project.Script'.error( 'This message will be logged at the ERROR level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
error
Logs an ERROR message to the underlying log engine of Martini, using a logger named Martini.
Example usage:
try { ... } catch ( Exception exception ) { 'This message will be logged at the ERROR level'.error( 'Could not perform operation', exception ); }- Parameters:
message- the message to logthrowable- the throwable to log- Returns:
- the message to log
- Since:
- 1.0
-
error
public static String error(@GloopParameter(allowNull=false) String loggerName, String message, Throwable throwable) Logs an ERROR message to the underlying log engine of Martini, using a logger named after
loggerName.Example usage:
try { ... } catch ( Exception exception ) { 'tld.organization.project.Script'.error( 'This message will be logged at the ERROR level', exception ) }- Parameters:
loggerName- the name of the loggermessage- the message to logthrowable- the throwable to log- Returns:
- the message to log
- Since:
- 1.0
-
errorIfEnabled
@GloopComment("Send an error message to the underlying log engine with category `Martini`, if error messages are enabled for the category") public static String errorIfEnabled(@GloopParameter("Message to print to log error") String message) Logs an ERROR message to the underlying log engine of Martini, using a logger named Martini. To succeed, ERROR messages must be enabled for said logger.
Example usage:
'This message will be logged at the ERROR level'.errorIfEnabled();
- Parameters:
message- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
errorIfEnabled
public static String errorIfEnabled(@GloopParameter(allowNull=false) String loggerName, String message) Logs an ERROR message to the underlying log engine of Martini, using a logger named after
loggerName. To succeed, ERROR messages must be enabled for said logger.Example usage:
'tld.organization.project.Script'.errorIfEnabled( 'This message will be logged at the ERROR level' )
- Parameters:
loggerName- the name of the loggermessage- the message to log- Returns:
- the message to log
- Since:
- 1.0
-
errorIfEnabled
Logs an ERROR message to the underlying log engine of Martini, using a logger named Martini. To succeed, ERROR messages must be enabled for said logger.
Example usage:
try { ... } catch ( Exception exception ) { 'This message will be logged at the ERROR level'.errorIfEnabled( exception ); }- Parameters:
message- the message to logthrowable- the throwable to log- Returns:
- the message to log
- Since:
- 1.0
-
errorIfEnabled
public static String errorIfEnabled(@GloopParameter(allowNull=false) String loggerName, String message, Throwable throwable) Logs an ERROR message to the underlying log engine of Martini, using a logger named after
loggerName. To succeed, ERROR messages must be enabled for said logger.Example usage:
try { ... } catch ( Exception exception ) { 'tld.organization.project.Script'.errorIfEnabled( 'This message will be logged at the ERROR level', exception ) }- Parameters:
loggerName- the name of the loggermessage- the message to logthrowable- the throwable to log- Returns:
- the message to log
- Since:
- 1.0
-
addFishTag
public static void addFishTag(@GloopParameter(allowNull=false) String key, @GloopParameter(allowNull=false) String value) Fish tagging is a technique in log4j wherein log statements are stamped with unique tags / information to allow for easier log tracing. Once tags are added, the key must be included in the log pattern of the appender set in /conf/overrides/log4j2.properties file in the following format:
${service:the-name-of-your-key}Example below will stamp logs in the martini log file:
appender.rolling.layout.pattern=%d{dd/MM/yy} ${service:the-name-of-your-key} %-5p [%c{1}] %m%n- Parameters:
key- key of the fish tagvalue- value of the fish tag
-
removeFishTag
Removes the fish tag denoted by the key specified- Parameters:
key- key of the fish tag
-
clearFishTags
public static void clearFishTags()Clears all previously added fish tags.
-