Namespace: Logger

Oracle® JavaScript Extension Toolkit (JET)
16.0.0

F83701-01

Since:
  • 1.0.0
Module:
  • ojlogger

QuickNav

Fields

Description

JET Logger

Logger object writes into the native browser console or a custom writer, if a custom writer is set as an option. To use a custom writer, implement the following writer methods: log(), info(), warn(), error()

When any of the logging methods is called, it compares the requested log level with the value of a log level option and logs the message if the log level is sufficient.

If the logging options are changed at a later point, the Logger will use the modified options for the subsequent log operations.

The logging level can be overridden via sessionStorage.setItem() call for the current browser session. Use 'ojet.logLevel' as the key with one of the following values: 'none' (least verbose), 'error', 'warning', 'info', 'log' (most verbose). Set the value in the browser console and refresh the browser in order for the value to take effect.

Session storage usage :


// override logging level for the current session
sessionStorage.setItem('ojet.logLevel', 'log');

All the logging methods support string formatting, accept variable number of arguments and accept a function as a parameter. When a callback function is specified as a parameter the function will be called if the log level is sufficient.

Logger usage :


//optional calls, see defaults
Logger.option("level",  Logger.LEVEL_INFO);
Logger.option("writer",  customWriter);  //an object that implements the following methods: log(), info(), warn(), error()

// logging a message
Logger.info("My log level is %d", Logger.option("level"));  // string formatting
Logger.warn("Beware of bugs", "in the above code");            // multiple parameters

// using a callback function as a parameter
Logger.info(function(){
   var foo = "This ";
   var bar = "is ";
   var zing = "a function";
   return foo + bar + zing;
});


Usage

Typescript Import Format
//This namespace exports multiple static methods or members. To import 
import * as Logger from "ojs/ojlogger";

//Now you can access the methods as Logger.methodName and so on

For additional information visit:


oj.Logger cannot be instantiated

Fields

(static, constant) LEVEL_ERROR :number

Log level error

(static, constant) LEVEL_INFO :number

Log level info

(static, constant) LEVEL_LOG :number

Log level - general message

(static, constant) LEVEL_NONE :number

Log level none

(static, constant) LEVEL_WARN :number

Log level warning

Methods

(static) error(message, optionalParams) : {void}

Writes an error message.
Parameters:
Name Type Argument Description
message any <optional>
A function that returns the message to be logged, a string containing zero or more substitution strings, or an object to be logged. See examples in the overview section above.
optionalParams any[] Objects with which to replace substitution strings within messages or simply additional objects to be logged.
Since:
  • 1.0.0
Returns:
Type
void

(static) info(message, optionalParams) : {void}

Writes an informational message.
Parameters:
Name Type Argument Description
message any <optional>
A function that returns the message to be logged, a string containing zero or more substitution strings, or an object to be logged. See examples in the overview section above.
optionalParams any[] Objects with which to replace substitution strings within messages or simply additional objects to be logged.
Since:
  • 1.0.0
Returns:
Type
void

(static) log(message, optionalParams) : {void}

Writes a general message.
Parameters:
Name Type Argument Description
message any <optional>
A function that returns the message to be logged, a string containing zero or more substitution strings, or an object to be logged. See examples in the overview section above.
optionalParams any[] Objects with which to replace substitution strings within messages or simply additional objects to be logged.
Since:
  • 1.0.0
Returns:
Type
void

(static) option(key, value) : {any}

Method for setting and getting logger option/options

Sets/gets logger configuration - level and/or writer. Accepts variable number of arguments.

Defaults:
Default level: oj.Logger.LEVEL_ERROR
Default writer: null; writes to the console

Usages:
oj.Logger.option(optionName) gets the value associated the the specified optionName
oj.Logger.option() gets an object containing key/value pairs representing the logger options hash
oj.Logger.option(optionName, value) sets the option value associated with optionName
oj.Logger.option(options) sets one or more options for the logger
Parameters:
Name Type Argument Description
key 'level' | 'writer' | {level?: any, writer?: any} <optional>
value any <optional>
Since:
  • 1.0.0
Returns:
Type
any

(static) warn(message, optionalParams) : {void}

Writes a warning message.
Parameters:
Name Type Argument Description
message any <optional>
A function that returns the message to be logged, a string containing zero or more substitution strings, or an object to be logged. See examples in the overview section above.
optionalParams any[] Objects with which to replace substitution strings within messages or simply additional objects to be logged.
Since:
  • 1.0.0
Returns:
Type
void