Logger


Packaged class

Namespace: overcast

The Logger provides methods for creating an entry in the Monitoring screen and outputting logs to the entries.
 

Constructors

 

Logger(runId)

Initializes a new instance of Logger using an existing overcast__Run__c record to output logs to. This constructor queries the database to get the log level of the Integration Scenario.

Signature

Logger(Id runId)

Parameters

runId

Type: Id

The ID of the overcast__Run__c record to output logs to.

When using this constructor, if the Id variable is a String type, you need to cast it to Id.

 

Logger(scenarioName)

Initializes a new instance of Logger that will create a new overcast__Run__c record for the specified Integration Scenario. The new record is not inserted into the database until commitToDatabase() is called. This constructor queries the database to get the ID and log level of the Integration Scenario.

See commitToDatabase() for the caveats with using this constructor.

Parameters

scenarioName

Type: String

The name of the Integration Scenario to create a new entry in the Monitoring screen.
 

Methods

 

addlog(messagelevel, message)

Add a log to the overcast__Run__c entry with the specified message text at the specified log level.

Signature

void addLog(String messageLevel, String message)

Parameters

messageLevel

Type: String

The log level as a String. Accepts log levels from the LogLevel enum. Invalid texts default to INFO.

message

Type: String

The message text to log.

Return Value

Type: void
 

addlog(logLevel, message)

Add a log to the overcast__Run__c entry with the specified message text at the specified log level.

Signature

void addLog(Integer logLevel, String message)

Parameters

logLevel

Type: Integer

The log level.

message

Type: String

The message text to log.

Return Value

Type: void

 

commitToDatabase()

Commit all pending changes to the database. This will insert or update the overcast__Run__c record, and insert any new logs as overcast__Log__c records. These records are the entries in the Monitoring screen.

This method will throw exceptions when there are failures to save. Failures to save generally are caused by insufficient permissions for the user (The user is missing the Overcast Real-time User permission set) or data storage limits exceeded.

Signature

void commitToDatabase()

Return Value

Type: void

Usage

This is called by the Overcast runtime after an Integration Scenario run has completed.

When a Logger is passed as a parameter to run a Real-time Integration Scenario, this method is not called by the Overcast runtime to allow multiple Real-time runs to be made.

If this method is called in a context that does not permit DML operations, then the records are delegated to an asynchronous process to perform the DML operation. These will appear in the Apex Job log screen.

If this method is called in a context that does not permit DML operations and the context is asynchronous, or batch, or the limit of future calls has been reached, then logging is skipped without raising an exception. No logs are cleared, either.

The log messages are cleared from the cache after calling this method. Subsequent calls will not duplicate records.

A Scenario Input value of NOT RUN is set by this method when the Logger is instantiated from the constructor that takes an Integration Scenario name (Logger(scenarioName)), but the Integration Scenario was not run (i.e., a request to the backend was not made). Either check before calling commitToDatabase() that the Scenario Input (getRun().overcast__Input__c) is not null, or that there are logs (hasLogs()).

 

getEndtime()

Gets the end time. If end time has not been previously set, returns null. When the commitToDatabase() method is called, this value is applied to the current overcast__Run__c record.

Signature

Datetime getEndtime()

Return Value

Type: Datetime

 

getCurrentLevel()

Gets the current log level for the logger. The current log level is determined in the constructors.

Signature

Integer getCurrentLevel()

Return Value

Type: Integer

 

getLogs()

Gets a list of all added logs.

Signature

List<overcast__Log__c> getLogs()

Return Value

Type: List<overcast__Log__c>

 

getRun()

Gets the current overcast__Run__c record that the log messages will be logged to. This record is the entry in the Monitoring screen. It is only inserted or updated when commitToDatabase() is called. Refer to the Logger constructors to see how the record is initialized.

Signature

overcast__Run__c getRun()

Return Value

Type: overcast__Run__c

 

getStatusCode()

Gets the value from overcast__StatusCode__c field on the current overcast__Run__c record.

Signature

Integer getStatusCode()

Return Value

Type: Integer

 

hasErrorCode()

Returns True if the status code is an error,( i.e., greater than or equal to 300 and less than 500).

Signature

Boolean hasErrorCode()

Return Value

Type: Boolean

 

hasLogs()

Gets a Boolean indicating if log messages have been added to the logger.

Signature

Boolean hasLogs()

Return Value

Type: void

 

logDebug(message)

Add a debug log to the overcast__Run__c entry with the specified message text.

Signature

void logDebug(String message)

Parameters

message

Type: String

The message text to log.

Return Value

Type: void

 

logError(message)

Add an error log to the overcast__Run__c entry with the specified message text.

Signature

void logError(String message)

Parameters

message

Type: String

The message text to log.

Return Value

Type: void

 

logInfo(message)

Add an info log to the overcast__Run__c entry with the specified message text.

Signature

void logInfo(String message)

Parameters

message

Type: String

The message text to log.

Return Value

Type: void

 

logWarning(message)

Add a warning log to the overcast__Run__c entry with the specified message text.

Signature

void logDebug(String message)

Parameters

message

Type: String

The message text to log.

Return Value

Type: void

 

setEndtime(endTime)

Sets the overcast__EndTime__c field for the current overcast__Run__c record.

Signature

void setEndtime(Datetime endTime)

Parameters

endTime

Type: Datetime

The time

Return Value

Type: void

Usage

This is set by the Overcast runtime after an Integration Scenario run has completed.

 

setEndtime()

Sets the overcast__EndTime__c field for the current overcast__Run__c record to the current date time.

Signature

void setEndtime()

Return Value

Type: void

 

setIdemId(idemId)

Sets the overcast__IdemId__c field for the current overcast__Run__c record.

Signature

void setIdemId(String idemId)

Parameters

idemId

Type: String

The unique identifier for this call.

Return Value

Type: void

Usage

This is set by the Overcast runtime when an Integration Scenario run has started.

 

setInputsetName(scenarioInput)

Sets the overcast__Input__c field for the current overcast__Run__c record.

Signature

void setInputsetName(String scenarioInput)

Parameters

scenarioInput

Type: String

The name of the Query Predicate or Data Set to run.

Return Value

Type: void

Usage

This is set by the Overcast runtime when an Integration Scenario run has started. See the help on Data Sets & Query Predicates for more information.

When using this to override the default UUID applied from running the scenario, call setInputsetName() after running the scenario.

 

setStatusCode(code)

Sets the overcast__StatusCode__c field for the current overcast__Run__c record.

Signature

void setStatusCode(Integer code)

Parameters

code

Type: Integer

The status code for the run.

Return Value

Type: void

Usage

This is set by the Overcast runtime after an Integration Scenario run has completed. See the help on Status Code for more information.

 

Static Methods

 

getHighestLogLevel(loglevels)

Gets the highest log level from the multiple scenarios. If there are no log levels set for any of the scenarios, return the global log level from the Overcast Settings. This does not query the database.

Signature

static String getHighestLogLevel(Map<Id, String> logLevels)

Parameters

logLevels

Type: Map<Id, String>

The output from Logger.getLogLevels(List<Id> runIds).

Return Value

Type: String

A log level name.

 

getLogLevel()

Gets the global log level. The global log level is set in the Overcast settings screen. This queries Custom Settings and not the database.

Signature

static String getLogLevel()

Return Value

Type: String

A log level name. Can be null if not set globally.

 

getLogLevel(runid)

Gets the log level for the specified Run record from the related Scenario record. This performs a database query.

Signature

static String getLoglLevel(Id runId)

Parameters

runId

Type: Id

An overcast__Run__c record ID. This queries the database for the log level of the overcast__Scenario__c record for the specified Run.

Return Value

Type: String

A log level name.

 

getLogLevels(runids)

Gets the log levels for all the specified Run records from the related Scenario records. This performs a database query.

Signature

static Map<Id, String> getLogLevels(List<Id> runIds)

Parameters

runIds

Type: List<Id>

A list of overcast__Run__c record IDs.

Return Value

Type: Map<Id, String>

A map of overcast__Run__c record IDs to log level names.

 

getLogLevelValue(logLevel)

Converts a log level name into a number. Returns 4 (INFO) if null or an unrecognized string is specified.

Signature

static Integer getLogLevelValue(String logLevel)

Parameters

logLevel

Type: String

A log level name.

Return Value

Type: Integer

A log level number.

 

getLogLevelValue(logLevel)

Converts the log level number into a name. Returns INFO if null or an out of bounds integer is specified.

Signature

static String getLogLevelValue(Integer logLevel)

Parameters

logLevel

Type: Integer

A log level number.

Return Value

Type: String

A log level name.

 

getScenarioLogLevel(scenId)

Gets the log level name set on the Scenario. If it is not set, gets the global log level name. This performs a database query.

Signature

static String getScenarioLogLevel(Id scenId)

Parameters

scenId

Type: Id

An overcast__Scenario__c record ID.

Return Value

Type: String

A log level name. Can be null if not set on the Scenario and not set globally.
 

Example - Log a Real-time Integration Scenario run

The example shows how to log the running of a Real-time Integration Scenario.

overcast.Logger logger = new overcast.Logger('MyScenario');

logger.addLog(overcast.LogLevel.INFO, 'Starting');

try {
    MyScenario request = new MyScenario();

    MyScenario response = request.run(logger, null);

    logger.addLog(overcast.LogLevel.INFO, 'Finished');
} catch (Exception e) {
    logger.addLog(overcast.LogLevel.ERROR, e.getMessage());
}

logger.commitToDatabase();


Example - Log multiple Real-time Integration Scenario runs.

This example shows how to log the running of two Real-time Integration Scenarios in the same transaction to the same entry in the Monitoring screen.

Check if the logger has any logs (shown in sample) before committing to the database to avoid creating an empty entry in the Monitoring screen. This can occur if an exception is thrown before the request to the backend system is made.

overcast.Logger logger = new overcast.Logger('MyScenario');

try {
    MyScenario request = new MyScenario();

    MyScenario response = request.run(logger, null);

    logger.addLog(overcast.LogLevel.INFO, 'First call completed. Running second call.');

    MyScenario request2 = new MyScenario();
    
    MyScenario response2 = request2.run(logger, null);
} catch (Exception e) {
    logger.addLog(overcast.LogLevel.ERROR, e.getMessage());
}

if (logger.hasLogs()) {
    logger.commitToDatabase();
}

Custom Exceptions