- Introduction
- C++ API
- JavaScript API
- Using custom logging providers
- Developing custom logging providers
Logging is a basic requirement for building services. napajs
logging API enables developers to integrate their own logging capabilities in both JavaScript and C++ (addon) world.
A log row may contain the following information:
- (Optional) Section: Useful field to filter log rows. Treatment is defined by logging providers.
- (Optional) Trace ID: Useful field to join logs in the same transaction or request.
- (Required) Message: Log message.
- (Required) Logging level:
- Error: for application error.
- Warn: for warning information.
- Info: for notification.
- Debug: for debugging purpose.
Include header: <napa.h>
Macros:
- LOG_ERROR(section, format, ...)
- LOG_ERROR_WITH_TRACEID(section, traceId, format, ...)
- LOG_WARNING(section, format, ...)
- LOG_WARNING_WITH_TRACEID(section, traceId, format, ...)
- LOG_INFO(section, format, ...)
- LOG_INFO_WITH_TRACEID(section, traceId, format, ...)
- LOG_DEBUG(section, format, ...)
- LOG_DEBUG_WITH_TRACEID(section, traceId, format, ...)
#include <napa.h>
void MyFunction() {
// ...
LOG_ERROR("init", "error: %s", errorMessage.c_str());
}
It logs a message. Using info level.
- A
log
is a shortcut forlog.info
.*
Example:
var napa = require('napajs');
napa.log('program started');
It logs a message with a section. Using info level.
Example:
napa.log('init', 'program started');
It logs a message with a section, associating it with a traceId. Using info level.
Example:
napa.log('request', 'A1B2C3D4', 'request received');
It logs an error message. Three variations of arguments are the same with the log
.
It logs a warning message. Three variations of arguments are the same with the log
.
It logs an info message. Three variations of arguments are the same with the log
.
It logs a debug message. Three combinations of arguments are the same with the log
.
Developers can hook up custom logging provider by calling the following before creation of any zones:
napa.runtime.setPlatformSettings({
"loggingProvider": "<custom-logging-provider-module-name>"
}
TBD