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

@monksoftware/monlog

v4.1.1

Published

Simple, sensible logging in one line.

Downloads

7

Readme

Monlog. Sensible logging by default.

Are you using console.log in your project? Are you tired of configuring loglevel / winston / whatever to add timestamp, colors to your log messages? Do you want a consistent log style? This is the library for you! You can now log with style -- no configuration required!

How to use

Works pretty much the same as loglevel, the only difference is that the exported root logger is preconfigured with loglevel-plugin-prefix and custom formatting functions in order to output nice colorful log messages with timestamp, log level and logger name.

const log = require('@monksoftware/monlog')

log.trace(msg)
log.debug(msg)
log.info(msg)
log.warn(msg)
log.error(msg)

Ready-to-go logging

You can use this library without any configuration, it will use sensible defaults resulting in nice, useful and production-ready log messages:

  • Millisecond-precision timestamp with timezone
  • (optionally) colored loglevel
  • Logger name
  • Log only warnings and errors
const log = require('@monksoftware/monlog')
const sublog = log.getLogger('SUB', log.levels.DEBUG)
log.warn('You can have nice log messages in just one line!')
sublog.debug("It's easy to define subloggers with different levels!")

// [2019-02-18T01:10:49.933+01:00] WARN [root]: You can have nice log messages in just one line!
// [2019-06-04T13:07:24.298+02:00] DEBUG [SUB]: It's easy to define subloggers with different levels!

Child loggers with custom format

const log = require('@monksoftware/monlog')
// Default level is WARN,
log.setDefaultLevel('DEBUG')
const childLogger = log.getLogger('CHILD', 'DEBUG', {
  template: 'When: %t, who: %n, why: %l, what: '
})
log.info('Child logger has been set up')
childLogger.debug('this is a debug message')
childLogger.info('This is a info message')
childLogger.warn('this is a warning message')
childLogger.error('this is an error message')

// [2019-02-18T01:08:46.260] INFO [root]: Child logger has been set up
// When: 2019-02-18T01:08:46.262+01:00, who: CHILD, why: DEBUG, what: this is a debug message
// When: 2019-02-18T01:08:46.262+01:00, who: CHILD, why: INFO, what: This is a info message
// When: 2019-02-18T01:08:46.262+01:00, who: CHILD, why: WARN, what: this is a warning message
// When: 2019-02-18T01:08:46.263+01:00, who: CHILD, why: ERROR, what: this is an error message

Advanced format customisation

You can use all loglevel-plugin-prefix customisations parameters:

const log = require('@monksoftware/monlog')

const advancedLogger = log.getLogger(
  'super-long-logger-name-maybe-too-much',
  'DEBUG',
  {
    // Only use first letter of level, e.g. W for waraning logs
    levelFormatter: (level) => level.toUpperCase()[0],
    // Numeric timestamp
    timestampFormatter: (date) => +date,
    // Truncate logger names to 5 letters
    nameFormatter: (name) => name.slice(0, 5),
    template: `#%l# logger: %n - timestamp: %t - message:`
  }
)

advancedLogger.info('I have strange taste for log messages...')
// #I# logger: super - timestamp: 1559646093854 - message: I have strange tasted for log messages...

Where do I configure the logging file/output ?

You don't. All applicaton logging should go to stdout and stderr. Log routing, dispatching and storage it's a deployment specific configuration and should therefore be in the hands of the sysadmin or be set up in the applicatoin packaging, it should not be decided by the applicaton source code. https://12factor.net/logs