Free Electron
Logging Guide

The logging system has these concepts:

With this structure logging groups can be flexibly configured without any hardcoded enumerations via defines, enums, or whatever.

A Static Logger object, named feLogger, is intended to be used for most logging. However, most logging calls will actually go through the feLog* macros.

Basic Logging

feLog("some logging message text\n");

Note that the trailing newline is not automatic.

The group for a basic log message is the MODULE macro, if defined, and is otherwise "default". FE's build system automatically sets MODULE to be the module name (such as "src.platform").

Logging to an Explicit Group

feLogGroup("my group", "some logging message text\n");

Direct Logging

feLogDirect("some logging message text\n");

Direct logging incurs minimum overhead and processing, and may be independently #ifdef disabled from normal logging. Direct logging has no group.

Controlling Output

Setting Up Named Log Objects

feLogger.setLog("stdout", new StdoutLog());

Binding Groups to Log Objects

feLogger.bind("src\.platform", "stdout");

Binding can use regular expressions, which is where a lot of the flexibility lies. Here is an example of binding all messages to stdout:

feLogger.bind(".*", "stdout");

Here is an example of binding all debug messages following a particular naming convention:

feLogger.bind(".*\.debug", "stdout");

Clearing a binding is done with the clear method:


Log Objects

Log objects take the vsprinted message and a map of attributes. File, line number, etc, all come in as attributes.

Default feLogger bindings

As with any binding, these can be cleared and reset, but as a default, feLogger is initialized like this in its constructor:

m_directLog = new StdoutLog();
setLog("stdout", m_directLog);
setLog("win32", new Win32Log());
bind(".*", "stdout");
bind(".*", "win32");