Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jj-log

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jj-log

Json logging module

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

jj-log

jj-log is a JSON logger that's as extendable as you want it to be.

Installation

$ npm install jj-log

Usage

Logging Strings

var jjLog = require( 'jj-log' )
var log = jjLog()

log( 'something happened!' )
// >> {"message":"something happened!", "timestamp":1430337665558}

Logging Objects

var jjLog = require( 'jj-log' )
var log = jjLog()

log({
    type: 'user_created',
    user: 'billbob@bill.com'
})
// >> {"type":"user_created", "user": "billbob@bill.com", "timestamp":1430337665558}

Without Timestamps

var jjLog = require( 'jj-log' )
var log = jjLog({
    timestamps: false
})

log({
    message: 'hello'
})
// >> {"message":"hello"}

With Default Data

var jjLog = require( 'jj-log' )
var log = jjLog({
    timestamps: false,
    defaults: {
        level: 'info',
        package: 'jj-log'
    }
})

log({
    message: 'hello'
})
// >> {"message":"hello","level":"info","package":"jj-log"}

With Additional Methods

var jjLog = require( 'jj-log' )
var log = jjLog({
    timestamps: false,
    methods: {
        fatal: {
            level: 'fatal',
            shouldWePanic: 'absolutely'
        },
        warn: {
            level: 'warn',
            shouldWePanic: 'probably not'
        }
    }
})

log.warn({
    message: 'hello'
})
// >> {"message":"hello","level":"warn","shouldWePanic":"probably not"}

log.fatal({
    message: 'hello'
})
// >> {"message":"hello","level":"fatal","shouldWePanic":"absolutely"}

Attributes May Be Functions

var fatalErrorsSoFar = 0
var jjLog = require( 'jj-log' )
var log = jjLog({
    timestamps: false,
    methods: {
        fatal: {
            level: 'fatal',
            errorNumber: function(){
                return fatalErrorsSoFar++
            }
        }
    }
})

log.fatal({
    message: 'oops'
})
// >> {"message":"oops","level":"fatal","errorNumber":1}

log.fatal({
    message: 'oops again'
})
// >> {"message":"oops again","level":"fatal","errorNumber":2}

Default May be Overriden at Any Level

var jjLog = require( 'jj-log' )
var log = jjLog({
    timestamps: false,
    defaults: {
        level: 'info'
    },
    methods: {
        warn: {
            level: 'warn'
        }
    }
})

log()
// >> {"level":"info"}

log({
    level: 'uh oh'
})
// >> {"level":"uh oh"}

log.warn()
// >> {"level":"info"}

log.warn({
    level: 'a bit worse this time'
})
// >> {"level":"a bit worse this time"}

jj-log May be Silenced for Debugging

var jjLog = require( 'jj-log' )
var log = jjLog({
    silent: true
})

log()
// >> no output

This can also be acheived by setting the SILENCE_JJ_LOG environment variable to true

Keywords

FAQs

Package last updated on 06 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc