Logging in ScriptCode
Available logging methods
In the ScriptCode environment, the object Logger, which allows logging events and data from the script.
Available logging methods:
function callService(context) {
Logger.info('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
Logger.debug('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
Logger.warn('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
Logger.error('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
Logger.trace('COMPLETE TASK EXECUTED [arg1={}, arg2={}]', 'arg1', 'arg2');
}Choosing the logging level
In ScriptCode, primarily use the level INFO. The most important errors and exceptions are logged automatically by the platform mechanisms.
Level
Principle of use in ScriptCode
INFO
Default logging level. Use for diagnostic and business information needed to trace the script's execution.
WARN
Use only in justified cases. Intended for significant and unusual situations requiring analysis.
ERROR
Do not use in ScriptCode. Errors requiring logging at the level ERROR are handled and logged by the platform.
DEBUG, TRACE
Use for detailed diagnostics during development. These logs are not available in test and production environments.
Business exceptions
In ScriptCode, trigger business errors using platform mechanisms: Business errors.
If the script throws a business exception, the platform automatically logs its occurrence at the level WARN. Do not additionally log the same event with Logger.warn() nor Logger.error().
Logging in try/catch blocks
In try/catch use primarily the level INFO.
Use the level WARN use only when the caught situation is significant and unusual enough to require later analysis.
Data logged by default
Platform Eximee automatically logs and treats as sensitive the following elements of the ScriptCode environment:
data input forms (
input),data output (
output),content requests (
request) sent to external services, e.g. via REST API,content responses (
response) received from those services.
This data is not printed in nonsensitive logs in a way that allows its actual content to be read. It is replaced with the markers _SENSITIVE_DATA_START_ ... _SENSITIVE_DATA_STOP_ or #hashed#, depending on the application type and execution context.
Sensitive and nonsensitive logging
If we want some of the data to be printed in nonsensitive logs without masking, we need to use the method nonsensitive(), which marks the passed argument as nonsensitive.
Example:
In this example:
arg1will be written to the log in plain form,arg2will be hidden (replaced with a sensitive data marker).
Use
nonsensitive()only when you are sure that the passed value does not contain sensitive data. If you are unsure, leave the value as sensitive.
Log format
Examples of log formats for different Eximee platform applications are shown below.
Application process-handlers
Application webforms
Best practices
For logging in ScriptCode, use only the object
Logger.By default, use the level
INFO.Use the level
WARNuse very rarely and only for significant, unusual situations requiring analysis.Do not use
Logger.error()- errors at the levelERRORare logged by the platform.Do not log input, output, request, or response data again if the platform is already logging them.
Do not log business exceptions again.
Use
nonsensitive()only for data that you are sure is not sensitive.Avoid logging entire objects, large data structures, and information that is not needed for diagnostics.
Last updated
Was this helpful?
