Log

3 minute readReferenceExtensibilityDeveloper productivity

This class provides methods to support the logging functionality of FlowPDF. Framework code uses special static instance.

A few points to note about logging.
  • The log level which is retrieved from the debugLevel property in the configuration, control which messages get written to the logs.

  • + The Methods provided by this class facilitate the classification of a

    message into any one of the following.
    • Log

    • Debug

    • Trace

    • Warning

    • Error

  • The log level and the classification of messages work together to surface the severity of a message.

  • Regardless of the log level Warning and Error Messages will always be written.

  • Logged messages are appropriately prefaced by [DEBUG], [TRACE], [WARNING], [ERROR] based on their classification.

It supports the following log levels:

  • INFO

    This is the default level.

    debugLevel property should be set to 0.

  • DEBUG

    Provides the same output from INFO level + debug output.

    debugLevel property should be set to 1.

  • TRACE

    Provides the same output from DEBUG level + TRACE output.

    debugLevel property should be set to 2.

Log can be used in two ways: With an instance. FlowPlugin contains a 'log' property with an initialized Log object that one can use:

void stepSampleStep(StepParameters sp, StepResult sr){ log.info("Sample info log message") log.setLogLevel(LOG_TRACE) log.trace("Sample trace log message") }

With static imported methods:

import static com.cloudbees.flowpdf.Log.* void stepSampleStep(StepParameters sp, StepResult sr){ logInfo("Sample log message") setDefaultLogLevel(LOG_TRACE) logTrace("Sample trace log message") }

Following methods are available for an instance.

setLogLevel(def newLogLevel)

Sets new instance log level.

Parameters

(Object) Should be a value that can be parsed as an integer. If value than 0 (Log.LOG_INFO), level 0 (Log.LOG_INFO) will be used. If a value is greater than 2 (Log.LOG_TRACE), level 2 (Log.LOG_TRACE) will be used.

Returns

Nothing

Usage

log.info("This is an info message");

info(Serializable…​ messages)

Logs an info message. Output is the same as from print function.

Parameters

(List of String) Log messages

Returns

Nothing

Usage

log.info("This is an info message");

debug(Serializable…​ messages)

Logs a debug message.

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written only if log level is DEBUG or higher. log.debug("This is a debug message");

trace(Serializable…​ messages)

Logs a trace message

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written only if log level is TRACE (the highest level). log.trace("This is a debug message");

warning(Serializable…​ messages)

Logs a warning message.

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written always (irrespective of the log level). log.warning("This is a warning message");

error(Serializable…​ messages)

Logs an error message

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written always (irrespective of the log level). log.error("This is an error message");

When using full static import, all the following methods can be used for logging:

setDefaultLogLevel(def newLogLevel)

Sets new static instance log level. Also, all new Log instances will have this log level.

Parameters

(Object) Should be a value that can be parsed as an integer. If value than 0 (Log.LOG_INFO), level 0 (Log.LOG_INFO) will be used. If a value is greater than 2 (Log.LOG_TRACE), level 2 (Log.LOG_TRACE) will be used.

Returns

Nothing

Usage

setDefaultLogLevel(0); // Log.LOG_INFO

logInfo(Serializable…​ messages)

Logs an info message. Output is the same as from print function.

Parameters

(List of String) Log messages

Returns

Nothing

Usage

logInfo("This is an info message");

logDebug(Serializable…​ messages)

Logs a debug message.

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written only if log level is DEBUG or higher. logDebug("This is a debug message");

logTrace(Serializable…​ messages)

Logs a trace message

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written only if log level is TRACE (the highest level). logTrace("This is a debug message");

logWarning(Serializable…​ messages)

Logs a warning message.

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written always (irrespective of the log level). logWarning("This is a warning message");

logError(Serializable…​ messages)

Logs an error message

Parameters

(List of String) Log messages

Returns

Nothing

Usage

// This message will be written always (irrespective of the log level). logError("This is an error message");