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

@17media/node-logger

v2.1.1

Published

Centralized logger for 17.Media Node.JS projects

Downloads

1,652

Readme

node-logger CircleCI npm (scoped) Coverage Status

Centralized logger for 17.Media Node.JS projects

... in the fires of Mount Doom, the dark lord Sauron forged, in secret, a master logger to control all others. "One logger to log them all!"

Usage

First of all you have to set up your configs:

import { Level } from '@17media/node-logger';

const loggerConfig = {
  // configs shared by all log services
  base: {
    // minimum level to trigger logger [ERROR|WARN|INFO|DEBUG]
    // levels lower than this will not be logged
    // it can be overridden in each service specific config
    logLevel: Level.INFO,

    // project name, preferably 'name' from package.json
    project: require('~/package.json').name,

    // environment [production|stage|development]
    environment: 'production',
  },

  // configs for slack
  Slack: {
    // override minimum log level (optional)
    logLevel: Level.WARN,

    // slack bot access token
    slackToken: SLACK_BOT_TOKEN,

    // slack channel to log messages to
    slackChannel: SLACK_BOT_ALERT_CHANNEL,
  },

  // configs for log collecting service (fluentD)
  Fluentd: {
    // override minimum log level (optional)
    logLevel: Level.INFO,

    // log collector URL
    collectorUrl: LOG_COLLECTOR_URL,
  },

  // configs for logging to console
  Console: {
    // override minimum log level (optional)
    logLevel: Level.ERROR,
  },
};

Then, there are two ways to continue, the easy way and the complete way:

Easy Way

This is the simple way and should cover ~90% of the use cases.

const logger = require('@17media/node-logger').createLogger(loggerConfig)('some:label');

logger.debug('track the variable value during development', { info });
logger.info('somehing worth logging for future reference', { additionalInfo });
logger.warn('somehing worth notice', { additionalInfo });
logger.error('somehing terrible happened', new Error());
logger.fatal('somehing disastrous happened', new Error(), { additionalInfo });

Complete Way

Provide configs to initiate the logger: A log service will be used only when all corresponding configs are provided.

const { Logger } = require('@17media/node-logger');
const logger = new Logger(loggerConfig);

Use the logger like:

const { LogMessage } = require('@17media/node-logger');

logger.Log(
  Level.WARN,
  new LogMessage('something happened', { additionalInfo }),
  'some:label:for:the:message'
);

In most situations you would want to pre-label all the messages logged in a file. You can do it by:

const labelledLogger = logger.Label('path:to:this:file');

labelledLogger.Log(
  Level.WARN,
  new LogMessage('something happened', { additionalInfo })
);

You can extend LogMessage and ErrorMessage to create customized formatting for your context.