Namespace: Logger

Oracle® JavaScript Extension Toolkit (JET)
7.1.0

F18183-01

QuickNav

Fields


Logger

Version:
  • 7.1.0
Since:
  • 1.0.0
Module:
  • ojlogger

Module usage

See JET Module Loading for an overview of module usage within JET.

Javascript Import Format
define(['ojs/ojlogger'], function(Logger) {
 // Application should call API on Logger 
})
Typescript Import Format
//This namespace exports multiple static methods or members. To import 
import * as Logger from "ojlogger";

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

JET In Typescript

A detailed description of working with JET elements and classes in your typescript project can be found at: JET Typescript Usage.

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.

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(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