Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

logbook

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logbook

Log all data passing through process.stdout and process.stderr

Source
npmnpm
Version
0.5.0
Version published
Weekly downloads
20
185.71%
Maintainers
1
Weekly downloads
 
Created
Source

Logbook

Yet another logger for Node.

Nothing fancy - logs all data that passes through process.stdout and process.stderr (console.log() and console.error()).

Features

  • Simple
    • Keep using console
  • Intercepts process.stdout and process.stderr producing two log levels:
    • LOG
    • ERR
  • Optionally log to:
    • Console
    • File
    • Loggly
    • XMPP (Google Talk)
    • Make your own

Usage

npm install logbook

Log to File

Disable console and log stdout stderr to log.txt and err.txt with a time stamp:

require('logbook').configure({
  console: {
    enabled: false
  },
  file: {
    enabled: true
  }
});

Log to Loggly

Disable console and send stdout stderr to Loggly (200MB/day free):

require('logbook').configure({
  console: {
    enabled: false
  },
  loggly: {
    enabled: false,
    inputToken: "abcd1234-1234-40bd-bddf-5ff562eb1cda"
  }
});

Log to XMPP a.k.a "Jabber" (Google Talk)

Disable console and send stderr to everyone in your contact list:

require('logbook').configure({
  console: {
    enabled: false
  },
  xmpp: {
    enabled: true,
    jid: '...@gmail.com',
    password: '...',
  }
});

To prevent too much spam, only stderr is logged by default. This can changed with xmpp.log: true.

Log to all the thingsss

require('logbook').configure({
  console: {
    enabled: true
  },
  file: {
    enabled: true,
    ...
  },
  loggly: {
    enabled: true,
    ...
  },
  xmpp: {
    enabled: true,
    ...
  }
});

See examples directory for more

Default Configuration

With this default configuration, logbook will have no effect, it will simply pass all output back the associated pipe (stdout or stderr).

<runFile('./show-defaults')>

{
  "console": {
    "enabled": true,
    "timestamps": false,
    "typestamps": false,
    "log": true,
    "err": true
  },
  "file": {
    "enabled": false,
    "timestamps": true,
    "typestamps": false,
    "log": "./log.txt",
    "err": "./err.txt"
  },
  "loggly": {
    "enabled": false,
    "inputToken": null,
    "maxSockets": 5,
    "log": true,
    "err": true
  },
  "xmpp": {
    "enabled": false,
    "jid": null,
    "password": null,
    "host": "talk.google.com",
    "port": 5222,
    "to": "*",
    "prefix": null,
    "delay": 100,
    "log": false,
    "err": true
  }
}

Custom Log Handlers

Add custom log handlers with add()

require('logbook').configure({
  ...
}).add(function(type, buffer) {
  type === 'log' || type === 'err';   //true
  buffer instanceof Buffer;           //true
});

API

Configure loggers with configure()

File

  • Writes will also append to each file

Loggly

Each log will be in the form

{
  type: "log|err"
  msg: "..."
}

This will be JSON encoded, so please only use HTTPS+JSON inputs!

inputToken

The token provided by loggly which identifies the input (or data bucket) that you're logging to.

XMPP

log

Boolean whether to send stdout, default false

err

Boolean whether to send stderr, default true

to

An array of jid Jabber IDs (Google Accounts in the case of Google Talk). By default it's the string "*", which means everyone in the given accounts contact list. Useful if you create a logbook Jabber account, then you can "subscribe" to it at will.

delay

This is the delay (in milliseconds) before all acculated messages are sent out. This helps trying to send thousands of messages concurrently resulting from a long synchronous loop.

prefix

This string will be prefixed to every message

Conceptual Overview

This module simply assigns a new functions to process.stdout|err.write. Captures all calls to it, calls the original versions when console.enabled true.

Todo

  • Make a CLI looking for a logbook.json file
    • Wraps logbook <script.js> logs all stdout stderr
    • Auto restarts, logging restart events
  • Add some tests

<license()>

Keywords

log

FAQs

Package last updated on 23 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts