ChartFactor Toolkit logs¶
Introduction¶
The logs of the ChartFactor Toolkit are a set of messages generated by ChartFactor Toolkit components. These messages are useful for debugging and monitoring the ChartFactor Toolkit behavior. These logs are sent to the the browser console or the Node console, depending on the environment.
Setting log levels¶
ChartFactor Toolkit components can generate logs of the levels below:
trace
: The most detailed log level. It is used to log detailed informationdebug
: This log level is used to log debugging informationinfo
: This log level is used to log informational messageswarn
: This log level is used to log warning messageserror
: This log level is used to log error messages
By default, the ChartFactor Toolkit log level is set to warn
. This means that only warning and error messages are printed. To change the log level, you can use the method below:
cf.setLogLevel(level, module)
The level
parameter is any of the supported log level values enumerated above. The module
parameter is optional and is the name of the module to set the log level for. Supported values are:
aktive
interaction-manager
standard
tables
geo-map-gl
geo-map
geo-map-v2
If the module
parameter is not provided, the log level applies for all modules. However, this does not override the log level of modules that were specifically set using the module
parameter.
Note
In the browser environment, log levels are persisted in local storage using the loglevel
key and the loglevel:{module}
key.
Example
1 2 3 4 5 6 7 8 9 10 11 |
|
Checking log levels¶
To check the actual log level of a module, you can use the method below:
cf.getLogLevel(module)
The module
parameter is optional and it is the name of the module to get the log level for. Supported values are:
aktive
interaction-manager
standard
tables
geo-map-gl
geo-map
geo-map-v2
If the module
parameter is not provided, the log level for all modules is returned.
Logging messages¶
To use the ChartFactor Toolkit to log messages, you can use the cf.log
object. This object has the following methods:
trace(message)
: Logs a message at thetrace
level.debug(message)
: Logs a message at thedebug
level.info(message)
: Logs a message at theinfo
level.warn(message)
: Logs a message at thewarn
level.error(message)
: Logs a message at theerror
level.
Example:
1 2 3 4 5 |
|
You can also create a logger for your own module like this:
const myLog = cf.getLogger("my-module")
Then you can change the log level for this module using the same methods as before.
Lazy evaluation¶
If you want to log a message that is expensive to compute, you can use the cf.lazyLog(level, callback, log)
method. This method takes three parameters:
level
: The log level of the messagecallback
: A function that returns the message to loglog
: (Optional) if you are using a custom logger, you can pass it here
Example:
1 2 3 4 5 6 7 |
|