Class: Logger

Oracle® JavaScript Extension Toolkit (JET)
3.2.0

E87541-01

QuickNav

Fields

oj. Logger

Version:
  • 3.2.0

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.

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.

Usage :


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

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

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

Constructor

new Logger()

oj.Logger cannot be instantiated
Source:

Fields

<static, constant> LEVEL_ERROR

Log level error
Source:

<static, constant> LEVEL_INFO

Log level info
Source:

<static, constant> LEVEL_LOG

Log level - general message
Source:

<static, constant> LEVEL_NONE

Log level none
Source:

<static, constant> LEVEL_WARN

Log level warning
Source:

Methods

<static> error(args)

Writes an error message.
Parameters:
Name Type Description
args ... The method supports a variable number of arguments, string substitutions and accepts a function as a parameter. See examples in the overview section above.
Source:

<static> info(args)

Writes an informational message.
Parameters:
Name Type Description
args ... The method supports a variable number of arguments, string substitutions and accepts a function as a parameter. See examples in the overview section above.
Source:

<static> log(args)

Writes a general message.
Parameters:
Name Type Description
args ... The method supports a variable number of arguments, string substitutions and accepts a function as a parameter. See examples in the overview section above.
Source:

<static> option(key, value)

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 Object | string <optional>
value Object | string <optional>
Source:
Example

Overriding default options

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

<static> warn(args)

Writes a warning message.
Parameters:
Name Type Description
args ... The method supports a variable number of arguments, string substitutions and accepts a function as a parameter. See examples in the overview section above.
Source: