Class: Logger

Oracle® JavaScript Extension Toolkit (JET)
5.0.0

E90577-01

QuickNav

Fields

Logger

Version:
  • 5.0.0
Since:
  • 1.0.0
Module:
  • ojcore

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;
});
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(args) → {void}

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

(static) info(args) → {void}

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

(static) log(args) → {void}

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

(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 * <optional>
Since:
  • 1.0.0
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) → {void}

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