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

onelog

v0.1.6

Published

A logging consolidation library

Downloads

2,081

Readme

OneLog

A simple logging consolidation library.

Don't be stuck with one logger, try them all without modification to your code.

Why?

I built this because I wanted to play around with different logging libraries without being locked into one.

Use one logging library for development and one for production.

Onelog provides a generic API to use so you can start adding logging statements and worry about which library to pick later.

Install

npm install onelog

NOTE: You must also install the logging library you wish to use (e.g. npm install log4js)

Usage

Configure which logging library to use (this example uses Log4js):

onelog = require 'onelog'
log4js = require 'log4js'
onelog.use onelog.Log4js

Add logging statements like this:

logger = require('onelog').get('Foo')
logger.info 'Hello, world!'

logger = require('onelog).get('Foo.Bar')
logger.debug 'FooBar!'

Configuration

I put all my library dependent configuration in a function so I can easily toggle between libraries.

configureLog4js = ->
  log4js = require 'log4js'
  # configure your logging library as usual
  # e.g. log4js.setGlobalLevel 'INFO'
  onelog.use onelog.Log4js

configureWinston = ->
  winston = require 'winston'
  onelog.use onelog.Winston

#configureWinston()
configureLog4js()

Connect/Express

app.use onelog.middleware,
  category: 'Middleware'

For Winson we use express-winston which provides two separate middlewares:

app.use onelog.middleware,
  winston:
   type: 'error'
app.use onelog.middleware,
  winston:
    type: 'request'
        
   

Supported libraries

Out-of-the-box supported libraries:

  • Winston
  • Log4js-node
  • Logule
  • Tracer
  • Caterpillar

It's easy to add support for another library. You just need to create a simple wrapper for the logging library that adheres to the Logger interface. Here's an example to add Log.js support.

CoffeeScript

class LogJS
  constructor: ->
    @Log = require 'log'
  get: (category) ->
    new @Log category
        
onelog.use LogJS

JavaScript

function LogJS() {
  this.Log = require("log");
}
Log.prototype.get = function(category) { new this.Log(category); }

onelog.use(LogJS);

Because Javascript lacks an equivalent for Ruby's method_missing we must manually provide all custom methods we wish to call on our Logger upfront. For example, if you were using the Winston library you might have written logger.emerg, but when switching to Log4js this level does not exist and throws an error. Therefore you will need the following:

onelog.use Log4js, methods: 'emerg'

This allows OneLog to send these events to the default logging level for the a library that doesn't support them. In the future there will be the option to map levels between libraries.

TODO

  • Tests.
  • Allow passthrough of non-standard Logger methods.
  • Add support for generic appender configuration.
  • Add a more thorough list of allowed methods.
  • Support setting global log level.
  • Expose hook to allow logging to cloud logging provider.

Thanks

consolidate.js for inspiration.