Skip to content

Latest commit

 

History

History
100 lines (81 loc) · 3.26 KB

log.md

File metadata and controls

100 lines (81 loc) · 3.26 KB

Function log

Table of Contents

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 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.

log is a shortcut for log.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 variation of arguments are the same with log.

log.warn(...)

It logs a warning message. Three variation of arguments are the same with log.

log.info(...)

It logs an info message. Three variation of arguments are the same with log.

log.debug(...)

It logs a debug message. Three combinations of arguments are the same with 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