npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oe-logger

v2.2.0

Published

Logger utility to log messages.

Downloads

75

Readme

Overview

Logger utility to log messages.

Usage

Once the logger is added to package.json and installed, it can be used in following way

var logger = require("oe-logger");
var log = logger("testlog");

log.debug(context, arg1, arg2);
log.info(context, arg1, arg2);
log.warn(context, arg1, arg2);
log.error(context, arg1, arg2);
log.fatal(context, arg1, arg2);

The log functions accepts atleast two parameters, * first parameter is context which would be the callContext for the request * second parameter onward can be String or Object as they will be printed as a concatenated string.

The logger requires a configuration to be passed as environment variable LOGGER_CONFIG. In case, no value is passed, then it uses default config, which is

{"logStreams": [{"type": "pretty"}],"levels": {"default": "info"}, "enableContextLogging": false}

Log Streams

Support for three log streams is provided, which are * Standard Output: Prints log as JSON on the console * Pretty Standard Output: Prints log in a pretty format on the console * UDP stream: Streams log to a udp stream using gelf

Following are examples for configuring them for different log streams (standard output, pretty output, udp stream) respectively,

export LOGGER_CONFIG={"logStreams":[{"type":"out"}],"levels":{"default":"debug"},"enableContextLogging":1}

export LOGGER_CONFIG={"logStreams":[{"type":"pretty"}],"levels":{"default":"debug"},"enableContextLogging":1}

export LOGGER_CONFIG={"logStreams":[{"type":"udp", "host":"127.0.0.1", "port":"1234"}],"levels":{"default":"debug"},"enableContextLogging":1}

export LOGGER_CONFIG={"logStreams":[{"type":"file","path":"./a.log","level":"debug"}],"levels":{"default":"debug"},"enableContextLogging":1}

export LOGGER_CONFIG={"logStreams":[{"type":"rotating-file","path":"./a.log","level":"debug", "period": "1d", "count": 3}],"levels":{"default":"debug"},"enableContextLogging":1}
Note: for rotating-file, following are optional, 
period - The period at which to rotate. This is a string of the format "$number$scope" where "$scope" is one of "ms" (milliseconds -- only useful for testing), "h" (hours), "d" (days), "w" (weeks), "m" (months), "y" (years). Or one of the following names can be used "hourly" (means 1h), "daily" (1d), "weekly" (1w), "monthly" (1m), "yearly" (1y). Rotation is done at the start of the scope: top of the hour (h), midnight (d), start of Sunday (w), start of the 1st of the month (m), start of Jan 1st (y).
count - The number of rotated files to keep.

Following are error log statement log.error({}, "sample log"); the output for out and pretty streams are as follows respectively:

{"name":"oe-logger","hostname":"HOSTNAME","pid":9940,"__name__":"test","level":50,"msg":"sample log","time":"2016-01-01T11:28:50.643Z","v":0}

[2016-01-01T11:28:29.126Z] ERROR: oe-logger on HOSTNAME: sample log (test)

Log Arguments

The first argument for the log statements can be call context, which allow to log modelName, remoteUser, tenantId and requestId related to the request being sent. These values are being placed in options/context of the request which can be passed as first argument to log them for easy filtering of requests.

Following is example to log a request details from the req-logging-filter, which passes the callContext as first argument for BaseUsers login API for admin user

log.debug(req.callContext, "Body: ", req.body);
[2017-07-11T06:20:55.726Z] DEBUG: oe-logger on HOSTNAME: Body:  {"username":"admin","password":"admin"} (req-logging-filter, BaseUsers, system, default, 18c036a0-6601-11e7-9cc9-fbb7d2f1cd6b)