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

easylog

v0.1.1

Published

Sensible winston setup

Downloads

18

Readme

easylog

A wrapper around winston to simplify configuration and log beautifully.

Table of Contents

Motivation

Winston is an excellent logging library that consists of easy to understand and easy to hack components. Getting started is relatively painless and there's a plethora of transports for various endpoints like files, console, databases, cloud services...

What winston lacks is the possiblity to configure the components without a lot of code. I found myself copy and pasting a wrapper class that sets up nice console formatting, sane log file locations, timer/profiling etc. I wanted a library that would make these customizations easy and whose behavior could be driven by one or more configuration files rather than code. easylog is that library.

Installation

npm install --save easylog

Usage

The module generates a default logging container and exports a constructor for child loggers.

The best way to use it is to pass it the current module. This way the logger will know for which file it logs events:

/* myFile.js */
var log = require('easylog')(module)

log.info("Life, Universe &c?", {'answer', 42});

Configuration

easylog can be configured by a JSON object that conforms to a JSON schema file. By default, the configuration will be searched, in order of preference:

  • A file easylog-development.json or easylog-production.json, depending on your $NODE_ENV
  • A file easylog.json
  • An easylog entry in the package.json

The full schema is comprehensive but you can specify only fragments of the configuraiton in the mentioned locations, the default config will be computed on the fly, see ./doc/default-config.json for a static copy of the default configuration file.

Log Patterns

easylog expects the log messages described as log-pattern macros. Please refer to the documentation of pre-defined macros there.

The default pattern for the log entry is:

'[%levelColor(%pad{-5}(%LEVEL))] ' +
'%levelColor(%date)' +
' |%label| ' +
'%message' +
'%meta'

The default pattern for the label is:

%pkg{name}' +
'%@{sep}(:)' +
'%@{name}(%path{%name})' +
'%?(%config{child})(' +
  '%@{sep}(#)' +
  '%@{child}(%config{child})' +
')'

Log the Logging

It can be tedious to debug why logging isn't working the way it's supposed to. You'd find yourself falling back to console.log et al to log the problems that prevent logging. To prevent you from this particular type of yak-shaving, easylog by default logs its own startup and every reload of configuration with level DEBUG.

API

node_env

The environemnt, i.e. development or production. This overrides the NODE_ENV environment variable and defaults to development.

easylog_level

The log level of easylog itself. For debugging purposes, this is set to debug by defualt. See Log the Logging.

root_dir_files

cwd

logdir

root_label

The label of the root logger, by default ROOT.

override_winston

If set, easylog will override the logger singleton that is returned when you require('winston'). This has the advantage that it will also enable your logging configuration for other logger that use winston. If set to true (the default) then winston.log will be overridden with easylog's root logger's log method.

injected_deps

injected_deps.winston

package_json

config_file_candidates