namespace sap/base/Log

Control sample: module:sap/base/Log
Visiblity: public
Available since: N/A
Module: sap/base/Log
Application Component:

A Logging API for JavaScript.

Provides methods to manage a client-side log and to create entries in it. Each of the logging methods module:sap/base/Log.debug, module:sap/base/Log.info, module:sap/base/Log.warning, module:sap/base/Log.error and module:sap/base/Log.fatal creates and records a log entry, containing a timestamp, a log level, a message with details and a component info. The log level will be one of module:sap/base/Log.Level and equals the name of the concrete logging method.

By using the module:sap/base/Log.setLevel method, consumers can determine the least important log level which should be recorded. Less important entries will be filtered out. (Note that higher numeric values represent less important levels). The initially set level depends on the mode that UI5 is running in. When the optimized sources are executed, the default level will be module:sap/base/Log.Level.ERROR. For normal (debug sources), the default level is module:sap/base/Log.Level.DEBUG.

All logging methods allow to specify a component. These components are simple strings and don't have a special meaning to the UI5 framework. However they can be used to semantically group log entries that belong to the same software component (or feature). There are two APIs that help to manage logging for such a component. With module:sap/base/Log.getLogger, one can retrieve a logger that automatically adds the given sComponent as component parameter to each log entry, if no other component is specified. Typically, JavaScript code will retrieve such a logger once during startup and reuse it for the rest of its lifecycle. Second, the module:sap/base/Log.setLevel(iLevel, sComponent) method allows to set the log level for a specific component only. This allows a more fine grained control about the created logging entries. module:sap/base/Log.getLevel allows to retrieve the currently effective log level for a given component.

module:sap/base/Log.getLogEntries returns an array of the currently collected log entries.

Furthermore, a listener can be registered to the log. It will be notified whenever a new entry is added to the log. The listener can be used for displaying log entries in a separate page area, or for sending it to some external target (server).


Nodes Overview

Node Description
sap/base/Log.Level

Enumeration of the configurable log levels that a Logger should persist to the log.


Methods Overview

Method Description
module:sap/base/Log.addLogListener

Allows to add a new LogListener that will be notified for new log entries.

The given object must provide method onLogEntry and can also be informed about onDetachFromLog, onAttachToLog and onDiscardLogEntries.

module:sap/base/Log.debug

Creates a new debug-level entry in the log with the given message, details and calling component.

module:sap/base/Log.error

Creates a new error-level entry in the log with the given message, details and calling component.

module:sap/base/Log.fatal

Creates a new fatal-level entry in the log with the given message, details and calling component.

module:sap/base/Log.getLevel

Returns the log level currently effective for the given component. If no component is given or when no level has been configured for a given component, the log level for the default component of this logger is returned.

module:sap/base/Log.getLogEntries

Returns the logged entries recorded so far as an array.

Log entries are plain JavaScript objects with the following properties

  • timestamp {number} point in time when the entry was created
  • level {module:sap/base/Log.Level} LogLevel level of the entry
  • message {string} message text of the entry
The default amount of stored log entries is limited to 3000 entries.

module:sap/base/Log.getLogEntriesLimit

Returns the maximum amount of stored log entries.

module:sap/base/Log.getLogger

Returns a dedicated logger for a component

The logger comes with the same API as the sap/base/Log module:

module:sap/base/Log.info

Creates a new info-level entry in the log with the given message, details and calling component.

module:sap/base/Log.isLoggable

Checks whether logging is enabled for the given log level, depending on the currently effective log level for the given component.

If no component is given, the default component of this logger will be taken into account.

module:sap/base/Log.logSupportInfo

Enables or disables whether additional support information is logged in a trace. If enabled, logging methods like error, warning, info and debug are calling the additional optional callback parameter fnSupportInfo and store the returned object in the log entry property supportInfo.

module:sap/base/Log.removeLogListener

Allows to remove a registered LogListener.

module:sap/base/Log.setLevel

Defines the maximum sap.base.log.Level of log entries that will be recorded. Log entries with a higher (less important) log level will be omitted from the log. When a component name is given, the log level will be configured for that component only, otherwise the log level for the default component of this logger is set. For the global logger, the global default level is set.

Note: Setting a global default log level has no impact on already defined component log levels. They always override the global default log level.

module:sap/base/Log.setLogEntriesLimit

Sets the limit of stored log entries

If the new limit is lower than the current limit, the overlap of old log entries will be discarded. If the limit is reached the amount of stored messages will be reduced by 30 percent.

module:sap/base/Log.trace

Creates a new trace-level entry in the log with the given message, details and calling component.

module:sap/base/Log.warning

Creates a new warning-level entry in the log with the given message, details and calling component.

module:sap/base/Log.addLogListener

Allows to add a new LogListener that will be notified for new log entries.

The given object must provide method onLogEntry and can also be informed about onDetachFromLog, onAttachToLog and onDiscardLogEntries.

Param Type DefaultValue Description
oListener object

The new listener object that should be informed

module:sap/base/Log.debug

Creates a new debug-level entry in the log with the given message, details and calling component.

Param Type DefaultValue Description
sMessage string

Message text to display

sDetails string ''

Details about the message, might be omitted

sComponent string ''

Name of the component that produced the log entry

fnSupportInfo function

Callback that returns an additional support object to be logged in support mode. This function is only called if support info mode is turned on with logSupportInfo(true). To avoid negative effects regarding execution times and memory consumption, the returned object should be a simple immutable JSON object with mostly static and stable content.

module:sap/base/Log.error

Creates a new error-level entry in the log with the given message, details and calling component.

Param Type DefaultValue Description
sMessage string

Message text to display

sDetails string ''

Details about the message, might be omitted

sComponent string ''

Name of the component that produced the log entry

fnSupportInfo function

Callback that returns an additional support object to be logged in support mode. This function is only called if support info mode is turned on with logSupportInfo(true). To avoid negative effects regarding execution times and memory consumption, the returned object should be a simple immutable JSON object with mostly static and stable content.

module:sap/base/Log.fatal

Creates a new fatal-level entry in the log with the given message, details and calling component.

Param Type DefaultValue Description
sMessage string

Message text to display

sDetails string ''

Details about the message, might be omitted

sComponent string ''

Name of the component that produced the log entry

fnSupportInfo function

Callback that returns an additional support object to be logged in support mode. This function is only called if support info mode is turned on with logSupportInfo(true). To avoid negative effects regarding execution times and memory consumption, the returned object should be a simple immutable JSON object with mostly static and stable content.

module:sap/base/Log.getLevel

Returns the log level currently effective for the given component. If no component is given or when no level has been configured for a given component, the log level for the default component of this logger is returned.

Param Type DefaultValue Description
sComponent string

Name of the component to retrieve the log level for

module:sap/base/Log.getLogEntries

Returns the logged entries recorded so far as an array.

Log entries are plain JavaScript objects with the following properties

The default amount of stored log entries is limited to 3000 entries.

Param Type DefaultValue Description

module:sap/base/Log.getLogEntriesLimit

Returns the maximum amount of stored log entries.

Param Type DefaultValue Description

module:sap/base/Log.getLogger

Returns a dedicated logger for a component

The logger comes with the same API as the sap/base/Log module:

Param Type DefaultValue Description
sComponent string

Name of the component which should be logged

iLogLevel module:sap/base/Log.Level

The default log level

module:sap/base/Log.info

Creates a new info-level entry in the log with the given message, details and calling component.

Param Type DefaultValue Description
sMessage string

Message text to display

sDetails string ''

Details about the message, might be omitted

sComponent string ''

Name of the component that produced the log entry

fnSupportInfo function

Callback that returns an additional support object to be logged in support mode. This function is only called if support info mode is turned on with logSupportInfo(true). To avoid negative effects regarding execution times and memory consumption, the returned object should be a simple immutable JSON object with mostly static and stable content.

module:sap/base/Log.isLoggable

Checks whether logging is enabled for the given log level, depending on the currently effective log level for the given component.

If no component is given, the default component of this logger will be taken into account.

Param Type DefaultValue Description
iLevel module:sap/base/Log.Level Level.DEBUG

The log level in question

sComponent string

Name of the component to check the log level for

module:sap/base/Log.logSupportInfo

Enables or disables whether additional support information is logged in a trace. If enabled, logging methods like error, warning, info and debug are calling the additional optional callback parameter fnSupportInfo and store the returned object in the log entry property supportInfo.

Param Type DefaultValue Description
bEnabled boolean

true if the support information should be logged

module:sap/base/Log.removeLogListener

Allows to remove a registered LogListener.

Param Type DefaultValue Description
oListener object

The new listener object that should be removed

module:sap/base/Log.setLevel

Defines the maximum sap.base.log.Level of log entries that will be recorded. Log entries with a higher (less important) log level will be omitted from the log. When a component name is given, the log level will be configured for that component only, otherwise the log level for the default component of this logger is set. For the global logger, the global default level is set.

Note: Setting a global default log level has no impact on already defined component log levels. They always override the global default log level.

Param Type DefaultValue Description
iLogLevel module:sap/base/Log.Level

The new log level

sComponent string

The log component to set the log level for

module:sap/base/Log.setLogEntriesLimit

Sets the limit of stored log entries

If the new limit is lower than the current limit, the overlap of old log entries will be discarded. If the limit is reached the amount of stored messages will be reduced by 30 percent.

Param Type DefaultValue Description
iLimit int Infinity

The maximum amount of stored log entries or Infinity for unlimited entries

module:sap/base/Log.trace

Creates a new trace-level entry in the log with the given message, details and calling component.

Param Type DefaultValue Description
sMessage string

Message text to display

sDetails string ''

Details about the message, might be omitted

sComponent string ''

Name of the component that produced the log entry

fnSupportInfo function

Callback that returns an additional support object to be logged in support mode. This function is only called if support info mode is turned on with logSupportInfo(true). To avoid negative effects regarding execution times and memory consumption, the returned object should be a simple immutable JSON object with mostly static and stable content.

module:sap/base/Log.warning

Creates a new warning-level entry in the log with the given message, details and calling component.

Param Type DefaultValue Description
sMessage string

Message text to display

sDetails string ''

Details about the message, might be omitted

sComponent string ''

Name of the component that produced the log entry

fnSupportInfo function

Callback that returns an additional support object to be logged in support mode. This function is only called if support info mode is turned on with logSupportInfo(true). To avoid negative effects regarding execution times and memory consumption, the returned object should be a simple immutable JSON object with mostly static and stable content.