Skip to content

Logging

Custom server-side code can log information using the API provided by Backendless SDK for JavaScript.

/* global Backendless */

Backendless.ServerCode.Persistence.beforeCreate('Order', function(req) {
    Backendless.Logging.setLogReportingPolicy( 1, 1 );
    var logger = Backendless.Logging.getLogger( "MyLogger");
    logger.info( "informational log message" ); 
    logger.warn( "warning message" ); 
    logger.debug( "debug message" ); 
    logger.error( "error message" ); 
    req.item.customername = req.item.customername.toUpperCase();
});

It is important to note that using logging in custom server-side code requires a special configuration of the logging policy using the following API. This is required to avoid creation of a log buffer and an additional thread responsible for submission of the log messages to the Backendless servers:

Backendless.Logging.setLogReportingPolicy( 1, 1 );

The sample code above logs four different messages, each for separate logging level. The log levels are organized into a hierarchy:

Log level
Includes messages from log levels
debug
debug, info, warn, error
info
info, warn, error
warn
warn, error
error
error

The log file is saved in the /logging directory of the Backendless File Service storage.

The following logging APIs are available:

Retrieving Logger object:

Backendless.Logging.getLogger( loggerName );

Log a message with the debug level:

loggerObject.debug( message );

Log a message with the info level:

loggerObject.info( message );

Log a message with the warn level:

loggerObject.warn( message );

Log a message with the error level:

loggerObject.error( message );