- 20 Feb 2025
-
DarkLight
-
PDF
Log Class
- Updated on 20 Feb 2025
-
DarkLight
-
PDF
The Log class is an Itential Platform class which is used to output errors, warnings, and other information to the console or the Itential Platform log files.
Accessing the Log Object
An instantiation of the Log class is made by Itential Platform on startup. It is exposed as the global log
object. Itential Platform applications and adapters may reference the log
object.
Example Cog File
The following is an example cog.js
file.
/* global adapters */
/* global brokers */
/* global cogs */
/* global log */
...
function test(callback){
log.info("I am a log entry");
...
}
function debug(callback){
log.debug("reconciling:"+device);
...
}
Log Levels
Log levels are used to control the amount of information recorded. Each level has a severity associated with it. The Log class offers several levels of logging.
Method | Description |
---|---|
console | Deprecated. |
spam | Collect or output excessive or repetitive messages, large text files, large quantities of data such as search results; information which though relevant would clutter up the log file and render it unusable. |
trace | Minor events within functions. Like "breadcrumbs" within a function. |
debug | Major events such as successful data retrieval from an external system or the completion of a function. |
info | Successful status change; should be limited to one message per successful action. |
warn | Issues or unexpected behavior which does not impact functionality. |
error | Errors or failures in the code which impacts functionality. |
console.log
should not be used as it is not supported by Itential Platform. The best practice is to use the log class.
Log levels are defined in the loggerProps
object of the Itential Platform Profile which can be configured within the Admin Essentials application.
- The
log_level
property determines the level for the log file. - The
console_level
property determines the level for the console. - In the Profile example below, the
log_level
is set toinfo
, which means any logging that has an equal or higher severity value than info will be written to/var/log/pronghorn/pronghorn.log
(info, warn, error, debug, console, trace). - If the
log_level
weredebug
, Itential Platform would monitor alllog.debug
messages through cogs and adapters and log that information.
Properties File
The following is an example of the loggerProps
object of an Itential Platform Profile:
...
"loggerProps": {
"description": "Logging",
"log_max_files": 100,
"log_max_file_size": 1048576,
"log_level": "info",
"log_directory": "/var/log/itential/",
"log_filename": "itential.log",
"log_timezone_offset": 0,
"console_level": "info"
},
...