Using the Logging Services

Logging in Equo applications is performed by Equo Loggers. There is an API for them in Java, JavaScript, and in a Node.js package.

Using the Logging Service from JavaScript

Equo provides and recognizes a set of defined functions to use in a JS script. The following table show the syntax and description of them:

Function Description

logDebug("")

Register an Debug Log declaring only a message

logInfo("")

Register an Info Log declaring only a message

logWarning("")

Register an Warning Log declaring only a message

logError("")

Register an Error Log declaring only a message

logTrace("")

Register an Trace Log declaring only a message

getJsLoggerLevel(callback)

Get the level of log configured for javascript logger. If not configured, the global level is used

setJsLoggerLevel(Level)

Set the level of log for javascript logger, ignoring global settings

getGlobalLoggerLevel(callback)

Get the global level of log for all loggers

setGlobalLoggerLevel(Level)

Set the global level of log for all loggers

The logger Levels are:

equo.LOG_LEVEL_OFF
equo.LOG_LEVEL_ERROR
equo.LOG_LEVEL_WARN
equo.LOG_LEVEL_INFO
equo.LOG_LEVEL_DEBUG
equo.LOG_LEVEL_TRACE
equo.LOG_LEVEL_ALL

// Level use to disable special logger level for javascript and use the global level
equo.LOG_LEVEL_NOT_CONFIGURED

And the use of the logger functions is done in this way:

equo.logInfo("An info log");

equo.setJsLoggerlevel(equo.LOG_LEVEL_DEBUG);

equo.logDebug("A debug log");

equo.getJsLoggerLevel(function(loggerLevel){
	alert("The current specific logger level is: " + loggerlevel);
});

An equivalent API is found in the @equo/logging Node package too, for those kind of projects.

Using the Logging Service from Java

Global Logger Configuration

To configure global settings, there is the LoggerConfiguration class with these static methods to configure global level of logs:

Function Description

getGlobalLevel()

Get the global level of log configured for all loggers

setGlobalLevel(Level)

Set the global level of log for all the loggers

Using the Loggers

The use of Equo Loggers in Java is very similar to the use of slf4j.

First, you have to get an instance of the logger for your class

import com.equo.logging.client.api.Logger;
import com.equo.logging.client.api.LoggerFactory;

public class YOURCLASS {
	static final Logger logger = LoggerFactory.getLogger(YOURCLASS.class);
...

Then, you can log at different levels with the methods debug, info, warn, error, or trace.

You can log a simple message:

logger.info("Log message");

A formatted message:

logger.info("Log {}", "message");

Or a message with a Throwable (an exception):

logger.error("Log message", new RuntimeException("Something Wrong"));

You can also get or set a specific level of log for some logger in particular with the following functions:

Function

Description

getLoggerLevel()

Get the level of log configured for the logger

setLoggerLevel(Level)

Set the level of log for the logger, ignoring global settings. Call it with null to use global settings

Logger Levels

The levels are:

OFF

ERROR

WARN

INFO

DEBUG

TRACE

ALL

Default logger level is INFO. To change it, run the app with a logger.level property. This can be done by adding the following argument to your execution: -Dlogger.level=DEBUG.