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

@lengoo/logger

v3.0.3

Published

Small winston wrapper tailored to lengoo needs

Downloads

2

Readme

Lengoo logger

Publish to NPM

Lengoo logger is a small wrapper of winston logger tailored to the team needs.

By default when used in development, it logs the defined events to the standard output, in production or staging, it can be connected to an APM agent and also write KPIs about the service.

Installation

To install this package is enough to execute:

npm install --save @lengoo/logger

Or for yarn users:

yarn add @lengoo/logger

Configuration

In order to make APM works, some configuration has to be provided in the form of environment variables, an example is as following:

APM_SERVER="http://localhost:8200"
APP_NAME="boilerplate"

If APM_SERVER is not defined in the environment, the logger will only print out to the stdout, will not write any kpi to the APM agent.

Handling environment variables

As mentioned before, all the configuration is managed by environment variables, there are some optionals and some other mandatories for the correct working of the library:

NODE_ENV=development
APP_NAME=<app_name> # mandatory, will define the name of the logs in the index.
APM_SERVER="http://localhost:8200" # optional, if not defined, will not connect to an APM server.

Usage

In order to use this library, you should import it first:

const Logger = require('@lengoo/logger');

There are different levels of logging that are defined by the severity of the event you want to log, in this package, the severity levels are being kept from winston, and are the following:

const levels = { 
  error: 0, 
  warn: 1, 
  info: 2, 
  verbose: 3, 
  debug: 4
};

Being each key a method in the package, you can log by calling them:

Logger.error('This is a message');

Structure

Each method contained by the package accepts either a string or an object, so it is possible to do something like:

Logger.error('This is an error message');
// or
Logger.error({
  code: 'not-found',
  message: 'Not Found',
  trace: err.stack.toString(),
})

In the first case, the resulting log will contain the following structure:

{
  "@timestamp": "2019-01-16T11:32:03.555Z",
  "message": "This is an error message",
  "severity": "error",
}

In the second case, you will have a little bit more complex structure:

{
  "@timestamp": "2019-01-16T11:32:03.555Z",
    "message": "Not found",
    "severity": "error",
    "fields": {
      "metadata": {
        "code": "not-found",
        "trace": "at hello_world.js line 1",
        "timestamp": "2019-01-16T11:32:03.552Z"
      }
    }
}

If you notice, you will always have consistency with timestamp, message and severity in the resulting log structure, and if you need to add extra data to the log, you can do it and this will be stored in a metadata field located inside fields object, this is meant for elasticsearch to keep consistency accross indices.