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:
aktiveinteraction-managerstandardtablesgeo-map-glgeo-mapgeo-map-v2providers(for data providers)
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:
aktiveinteraction-managerstandardtablesgeo-map-glgeo-mapgeo-map-v2providers(for data providers)
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 thetracelevel.debug(message): Logs a message at thedebuglevel.info(message): Logs a message at theinfolevel.warn(message): Logs a message at thewarnlevel.error(message): Logs a message at theerrorlevel.
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 | |
ChartFactor Node logs¶
ChartFactor data provider modules such as BigQuery, Databricks, Elasticsearch, and Redshift/Postgres can be deployed in a Node environment. The log levels and output produced by these modules can be managed as described below.
log levels¶
You can set the log levels using the environment variables CF_LOG_LEVEL_PROVIDERS and CF_LOG_LEVEL_AKTIVE.
CF_LOG_LEVEL_PROVIDERS: This variable sets the log levels for data providers. Supported values are the same as the ones used in the browser environment:trace,debug,info,warn, anderror.CF_LOG_LEVEL_AKTIVE: This variable sets the log levels for theaktivemodule. Supported values are alsotrace,debug,info,warn, anderror.
If both variables are set, their respective log levels will apply. Otherwise, the warn default level will be used.
log outputs¶
In a Node environment, the ChartFactor Toolkit logs are sent to the console by default.
You can set the log output to a specific file by providing a method factory as illustrated below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
In the example above, the CF_LOG_PATH environment variable will be used to determine the path to the chartfactor log file. Please refer to the ChartFactor Node project which you can use as a reference implementation on how to write data provider logs to a file.