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

fwsp-logger

v0.4.0

Published

Provides logging via pino, and transport to elasticsearch

Downloads

171

Readme

Logger npm version

Summary

Provides a pino logger that ships its logs to elasticsearch, with rotating index support.

Usage

See Configuration for details on the logger plugin config options.

Use the HydraExpressLogger plugin for Hydra Express apps:

const HydraExpressLogger = require('fwsp-logger').HydraExpressLogger;
hydraExpress.use(new HydraExpressLogger());
hydraExpress.init(...);
hydraExpress.appLogger.info('information', {and: 'an object', with: 'some stuff'});
hydraExpress.appLogger.error({err: new Error('this will log a stack trace')});

// in a request handler
req.log.info('this will also log information about the current request');
req.log.error({err: new Error('this will log a stack trace')});

with corresponding entry in config.json:

"hydra": {
  "plugins": {
    "logger": {
      "serviceName": "foo-service",
      "toConsole": false,
      "noFile": true,
      "elasticsearch": {
        "host": "localhost",
        "port": 9200,
        "index": "local-dev"
      }
    }
  }
}

Or, use the HydraLogger plugin for Hydra services:

const HydraLogger = require('fwsp-logger').HydraLogger;
let hydraLogger = new HydraLogger();
let log = hydraLogger.getLogger();
hydra.use(hydraLogger);
hydra.init(...);
// use via hydra (recommended)
hydra.log('info', 'some info');
hydra.log('error', 'just a message, no stack trace');
// or use directly - useful if you need a stack trace
log.info('some info');
log.error({err: new Error('error with stack trace')});
log.error('just a message, no stack trace');

General usage (outside of Hydra):

const PinoLogger = require('fwsp-logger').PinoLogger,
      logger = new PinoLogger(
        {
          serviceName: 'my-app',             /* required - name of the app writing logs */
          logPath: '/custom/log-file.log',   /* optional, defaults to ${cwd()}/serviceName.log */
          elasticsearch: {
            host: 'your.elasticsearch.host.com',
            port: 9200,
            index: 'local-dev'
          }
        }
    );
const appLogger = logger.getLogger();
appLogger.error({err: 'An error happened'}); // pass {err} literal for proper error serialization
appLogger.info({
    message: 'Something else happened',
    details: {
      foo: 'bar',
      answer: 42
    }
});

Configuration

| Field | Description | Required | Default | --- | --- | ---| --- | serviceName | Name of the service doing the logging | N | hydra.serviceName | logPath | Path to log to if !noFile | N | service/servicename.log | toConsole | Log to console (stdout)? | N | true | noFile | Don't write log to disk | N | false | redact | Fields to redact (e.g. passwords, credit card numbers, etc.) | N | [] | elasticsearch | Connection object for ElasticSearch | N | none | rotate | How often to rotate ES index [daily\|monthly\|yearly] | N | No rotation by default

Testing

To make sure logs are getting shipped to Elasticsearch, you can spin up docker containers with ES and Kibana using the docker-compose.yml file in this repository.

You will need docker and docker-compose installed, then in this project folder, launch docker-compose up.

You'll need to set up an Elasticsearch index in Kibana before you'll be able to view logs, which should be the value of logger.elasticsearch.index (local-dev in above examples), or pino by default.

If you don't have any index patterns set up, Kibana won't let you proceed without adding one. Otherwise, to add additional indices, go to Settings -> Indices.

License

Licensed under MIT.