Class LoggerMethods
- java.lang.Object
- 
- io.toro.martini.LoggerMethods
 
- 
 public final class LoggerMethods extends Object 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 SummaryFields Modifier and Type Field Description (package private) static ThreadLocal<Map<String,String>>CONTEXT_MAP
 - 
Constructor SummaryConstructors Constructor Description LoggerMethods()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static 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 voidclearFishTags()Clears all previously added fish tags.static Stringdebug(String message)Logs a DEBUG message to the underlying log engine of Martini, using a logger named Martini.static Stringdebug(String loggerName, String message)Logs 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 Stringerror(String message)Logs an ERROR message to the underlying log engine of Martini, using a logger named Martini.static Stringerror(String loggerName, String message)Logs an ERROR message to the underlying log engine of Martini, using a logger named afterloggerName.static Stringerror(String loggerName, String message, Throwable throwable)Logs an ERROR message to the underlying log engine of Martini, using a logger named afterloggerName.static Stringerror(String message, Throwable throwable)Logs 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 Stringinfo(String message)Logs an INFO message to the underlying log engine of Martini, using a logger named Martini.static Stringinfo(String loggerName, String message)Logs 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.ApplicationLoggerlogger()Get a logged named groovy.static ApplicationLoggerlogger(Class clazz)Get a logger named after a class.static ApplicationLoggerlogger(String scriptName)Get a logger named after a script.static StringlogTo(String message, String scriptName)Log a message using a logger named afterscriptName.static Stringprint(String message)Print a message using {@link System#out#print(String)}.static Stringprintln(String message)Print a message using {@link System#out#println(String)}.static voidremoveFishTag(String key)Removes the fish tag denoted by the key specifiedstatic Stringtrace(String message)Logs a TRACE message to the underlying log engine of Martini, using a logger named Martini.static Stringtrace(String loggerName, String message)Logs 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 Stringwarn(String message)Logs a WARN message to the underlying log engine of Martini, using a logger named Martini.static Stringwarn(String loggerName, String message)Logs 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 Detail- 
CONTEXT_MAPstatic final ThreadLocal<Map<String,String>> CONTEXT_MAP 
 
- 
 - 
Method Detail- 
printpublic static String print(String message) Print a message using {@link System#out#print(String)}.- Parameters:
- message- the message
- Returns:
- the printed message
- Since:
- 1.0
 
 - 
printlnpublic static String println(String message) Print a message using {@link System#out#println(String)}.- Parameters:
- message- the message
- Returns:
- the printed message
- Since:
- 1.0
 
 - 
loggerpublic static ApplicationLogger logger(String scriptName) 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
 
 - 
loggerpublic static ApplicationLogger logger(Class clazz) 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
 
 - 
loggerpublic ApplicationLogger 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
 
 - 
logTopublic static String logTo(String message, String scriptName) 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 log
- scriptName- the name of the logger
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
tracepublic static String trace(String message) 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
 
 - 
tracepublic static String trace(@GloopParameter(allowNull=false) String loggerName, String message) 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
traceIfEnabledpublic static String traceIfEnabled(String message) 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
 
 - 
traceIfEnabledpublic 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
debugpublic static String debug(String message) 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
 
 - 
debugpublic static String debug(@GloopParameter(allowNull=false) String loggerName, String message) 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
debugIfEnabledpublic static String debugIfEnabled(String message) 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
 
 - 
debugIfEnabledpublic 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
infopublic static String info(String message) 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
 
 - 
infopublic static String info(@GloopParameter(allowNull=false) String loggerName, String message) 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
infoIfEnabledpublic static String infoIfEnabled(String message) 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
 
 - 
infoIfEnabledpublic 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
warnpublic static String warn(String message) 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
 
 - 
warnpublic static String warn(@GloopParameter(allowNull=false) String loggerName, String message) 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
warnIfEnabledpublic static String warnIfEnabled(String message) 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
 
 - 
warnIfEnabledpublic 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
errorpublic static String error(String message) 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
 
 - 
errorpublic static String error(@GloopParameter(allowNull=false) String loggerName, String message) 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
errorpublic static String error(String message, Throwable throwable) 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 log
- throwable- the throwable to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
errorpublic 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 logger
- message- the message to log
- throwable- 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
 
 - 
errorIfEnabledpublic 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 logger
- message- the message to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
errorIfEnabledpublic static String errorIfEnabled(String message, Throwable throwable) 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 log
- throwable- the throwable to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
errorIfEnabledpublic 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 logger
- message- the message to log
- throwable- the throwable to log
- Returns:
- the message to log
- Since:
- 1.0
 
 - 
addFishTagpublic 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 tag
- value- value of the fish tag
 
 - 
removeFishTagpublic static void removeFishTag(@GloopParameter(allowNull=false) String key) Removes the fish tag denoted by the key specified- Parameters:
- key- key of the fish tag
 
 - 
clearFishTagspublic static void clearFishTags() Clears all previously added fish tags.
 
- 
 
-