4.4 Logging Functions (formula.log)

4.4.1 log

The log object contained under the formula object is a gateway for the logging activities of the Operations Center server or client, depending on which one invokes the script:

  • If on the client, log messages are written to the Client's java console output.

  • If on the server, the log messages are handled by the server's log4j implementation. For more information regarding server trace logs and log settings, see the Operations Center Server Configuration Guide.

Four methods that can log messages:

  • debug(): Send a debug message to the log.

  • info(): Send an informational message to the log.

  • warn(): Send a warning message to the log.

  • error(): Send an error message to the log.

For example:

formula.log.info( 'An informational message' )
formula.log.error( 'An error happened' )

4.4.2 logCategory

The logCategory of a script contains the name of the logging category that produces messages for the script. This property can be obtained or set.

To change or switch the logging category of a script, simply set this variable to another string. For example:

formula.logCategory = 'Script.MyScript'
formula.log.warn( 'Something bad might have just happened' )

4.4.3 Creating a New Log Instance

It might be necessary to create a separate log instance than the one provided for a script. To do this, call the getCategory() method on the log object:

formula.log.getInstance( ‘Another.Category' )

Use a period to separate categories. For example:

var otherlog = formula.log.getInstance( 'Script.Other' )
otherlog.info( 'Now logging to another log category' )