Function log
October 29, 2018 ยท View on GitHub
Table of Contents
- Introduction
- C++ API
- JavaScript API
- Using custom logging providers
- Developing custom logging providers
Introduction
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.
C++ API
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());
}
JavaScript API
log(message: string): void
It logs a message. Using info level.
- A
logis a shortcut forlog.info.*
Example:
var napa = require('napajs');
napa.log('program started');
log(section: string, message: string): void
It logs a message with a section. Using info level.
Example:
napa.log('init', 'program started');
log(section: string, traceId: string, message: string): void
It logs a message with a section, associating it with a traceId. Using info level.
Example:
napa.log('request', 'A1B2C3D4', 'request received');
log.err(...)
It logs an error message. Three variations of arguments are the same with the log.
log.warn(...)
It logs a warning message. Three variations of arguments are the same with the log.
log.info(...)
It logs an info message. Three variations of arguments are the same with the log.
log.debug(...)
It logs a debug message. Three combinations of arguments are the same with the log.
Using custom logging providers
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>"
}
Developing custom logging providers
TBD