Table of Contents

Javascript binding API - Eina Logging

Back to the JS Eina page

The Eina framework provides a comprehensive system to manage logging events in your application. For example, it can group message in domains, assign different levels to the messages. There's also the possibility of intercepting the log messages, allowing further processing.

The main workhorse is efl.log_print. It will call the function defined in efl.log_print_cb_set, defaulting to a function that will print to the stderr. You can pass many options to log_print to control the output.

Constants

Levels

The log levels are ranked according to their usual severity. For example, critical errors can be configured to abort the application while debug messages are usually required only in development or when triaging bugs. In descending order of severity:

The levels are also ordered numerically, with the most severe (CRITICAL) being the smallest value and the least severe (DBG) the largest value.

State

The states are used in efl.logTiming to indicate transitions in phases for a given domain.

Domain

Log domains are used to group messages, like messages from different modules, different features, etc. You can filter domains by means of log levels through efl.log_domain_level_set. They are represented by a name that you pass to efl.registerLogDomain and an id (integer) that it returns.

By default, Eina offers a global domain to be used by the application.

Colors

The logging system uses the terminal colors format to specify a color for a given domain. With the default callback, only the domain name is shown with the given color. Currently, the following string constants are exported as shortcuts:

Environment Variables

A number of environment variables affect the behavior of the log module. These are:

Functions

checkLogLevel(level)

Syntax

var willBeLogged = efl.checkLogLevel(level);

Parameters

Return value

Checks whether the given log level will be logged or ignored.

getLogAbortOnCritical()

Syntax

var willAbortOnCritical = efl.getLogAbortOnCritical();

Return value

Returns true if events with level equal or smaller to efl.getLogAbortOnCriticalLevel() should abort the program.

getLogAbortOnCriticalLevel()

Syntax

var abortLevel = efl.getLogAbortOnCriticalLevel();

Return type

Returns the least severe (largest numerically) level that will trigger the program termination upon happening. Events most severe than the value returned also trigger termination.

getLogColorDisable()

Syntax

var colorDisabled = efl.getLogColorDisable();

Return type

Determines whether colors are disabled in the log messages.

getLogDomainLevel(domain)

Syntax

var level = efl.getLogDomainLevel(domainname);

Parameters

Return type

Gets the domain level given its name. If the domain was not yet registered through efl.registerLogDomain but is pending after a previous efl.setLogDomainLevel call or the environment variable EINA_LOG_LEVELS, the respective value is returned. If nothing else was found, the default level from efl.getLogLevel is returned.

getLogDomainRegisteredLevel(name)

Syntax

var level = efl.getLogDomainRegisteredLevel(domain);

Parameters

Return type

Gets the level for the given domain. Works much faster than efl.getLogDomainLevel but relies on the domain being previously registered with efl.registerLogDomain.

getLogFileDisable()

Syntax

var isFileDisabled = efl.getLogFileDisabled();

Return type

Returns whether the originating file name is disabled from log messages.

getLogFunctionDisable()

Syntax

var isFunctionDisabled = efl.getLogFunctionDisabled();

Return type

Returns whether the originating function name is disabled from log messages.

getLogLevel()

Syntax

var default_level = efl.getLogLevel();

Return type

Returns the default log level. Messages less severe than this level will be ignored by efl.logPrint.

logCritical(message)

Syntax

efl.logCritical(message);

Parameters

Helper wrapper around efl.logPrint that prints a message with efl.LOG_LEVEL_CRITICAL to the global domain.

logDebug(message)

Syntax

efl.logDebug(message);

Parameters

Helper wrapper around efl.logPrint that prints a message with efl.LOG_LEVEL_DBG to the global domain.

logError(message)

Syntax

efl.logError(message);

Parameters

Helper wrapper around efl.logPrint that prints a message with efl.LOG_LEVEL_ERR to the global domain.

logInfo(message)

Syntax

efl.logInfo(message);

Parameters

Helper wrapper around efl.logPrint that prints a message with efl.LOG_LEVEL_INFO to the global domain.

logPrint(domain, level, message)

Syntax

efl.logPrint(domain, level, message)

Parameters

Prints the string message related domain with severity level. If level is of a lower severity (higher numerical value) than the value from efl.getLogLevel, the call is ignored.

For the global domain, you can use the helper functions efl.logCritical, efl.logInfo and related.

Example usage:

efl.logPrint(efl.LOG_DOMAIN_GLOBAL, efl.LOG_LEVEL_WARN, "Warning. Exclamation point. Warning.");
efl.logPrint(mydomain, efl.LOG_LEVEL_INFO, "Information. We want information.");

logTiming(domain, state, phase)

Syntax

efl.logTiming(domainId, state, phase);

Parameters

Starts or stop the timing of a phase. If given efl.LOG_STATE_START, it assumes the previously started phase has stopped.

logWarning(message)

Syntax

efl.logWarning(message);

Parameters

Helper wrapper around efl.logPrint what prints a message with efl.LOG_LEVEL_WARN to the global domain.

registerLogDomain(name, color)

Syntax

var domainId = efl.registerLogDomain(domainname, color);

Parameters

Registers a new domain with name name and color color. The returned id will be used to reference the domain on the other log functions. If a negative number is returned, a log event occurred.

Example usage

var myid = efl.registerLogDomain("mydomain", efl.COLOR_CYAN);

setLogAbortOnCritical(boolvar)

Syntax

efl.setLogAbortOnCritical(boolvar);

Parameters

Sets whether the program should terminate upon a logging event with a level at least of the same severity of efl.getLogAbortOnCriticalLevel.

Upon initializaton, it takes the value from the environment variable EINA_LOG_ABORT.

setLogAbortOnCriticalLevel(level)

Syntax

efl.setLogAbortOnCritical(level);

Parameters

Sets the minimal message level the program should check if it should abort. Messages less severe than level are ignored for this check.

Upon initializaton, it takes the value from the environment variable EINA_LOG_ABORT_LEVEL.

setLogColorDisable(bool)

Syntax

efl.setLogColorDisable(boolvar);

Parameters

Sets whether the colored logging should be disabled or not.

setLogDomainLevel(domainname, level)

Syntax

efl.setLogDomainLevel(name, level);

Parameters

Sets the trigger level for a given domain with name name. It works like setting the environment variable EINA_LOG_LEVELS=<name>:<level>.

If the domain name was not registered before, it is marked as a pending set and is applied upon registration.

setLogDomainRegisteredLevel(domainname, level)

Syntax

efl.setLogDomainRegisteredLevel(name, level);

Parameters

Sets the trigger level for a given domain with name name. It's a much faster version of efl.setLogDomainLevel, requiring a previously registered domain.

setLogFileDisable(bool)

Syntax

efl.setLogFileDisable(boolvar);

Parameters

Sets whether the filename logging should be disabled or not.

setLogFunctionDisable(enable)

Syntax

efl.setLogFunctionDisable(boolvar);

Parameters

Sets whether the function name logging should be disabled or not.

setLogLevel(level)

Syntax

efl.setLogLevel(level);

Parameters

Sets the default level for log events. Messages less severe (higher numerical value) than level will be ignored.

Upon initialization, the default level is set to the value from the environment variable EINA_LOG_LEVEL.

setLogPrintCb(callback)

Syntax

function callback(name, color, level, file, func, line, message){...}
efl.setLogPrintCb(callback);

Parameters

Sets the callback that will be called whenever a log command would be executed, i.e., above or equal to the current log level, is called. It receives as arguments the domain, output color, level, filename, function and line number of the call, and finally the message. It allows further customization of the output.

If not set, EFL defaults the output to the standard error output, like this:

CRI<30206>: /home/user/dev/myapp/main.js:254 () MessageFrom logPrint

Example usage

function mycallback(domain, color, level, file, func, line, message) {
    // Save log to file, print, etc.
}
 
efl.setLogPrintCb(callback);
efl.logWarning("Kaboom"); // Calls mycallback if efl.LOG_LEVEL_WARN is a triggering level.

unregisterLogDomain(domainId)

Syntax

efl.unregisterDomain(domain);

Parameters

Forgets about a logging domain registered from efl.registerLogDomain.