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

log4json

v1.2.1

Published

JSON wrapper for log4js

Downloads

64

Readme

NPM

Github Actions

Dependency Status DevDependency Status PeerDependency Status

Log4JSON

JSON layout for log4js. Zero dependency and super slim.

Options

separator (default: ' ')

Once you have multiple messages as in string format, logger will concat all of them and needs a separator. This value will be used while concatenating the strings.

space (default: null)

This parameter will help you to format your output. By default, it will log whole output in one line, otherwise multilines. Please check the space argument on JSON.stringify() documentation.

omitDefaultCategory (default: true)

In order to reduce the redunnant log size, default category name will be omitted. In case of you want to have category name as always. You can force logger to include category name even when it is deafult

props

Any of the property names can be overridden. You can override all field names on output. Default propery names are;

{
  "ts": "ts",
  "level": "level",
  "category": "category",
  "stack": "stack",
  "message": "message",
  "callStack": "callStack"
}

Full Example

https://runkit.com/salimkayabasi/log4json

const log4js = require('log4js');
const log4json = require('log4json');

addLayout('log4json', log4json);

configure({
  appenders: {
    log4json: {
      type: 'console',
      layout: {
        type: 'log4json',
        separator: ' | ',
        space: 2,
        omitDefaultCategory: false,
        props: {
          ts: '@timestamp',
          level: 'lvl',
          category: 'cat', // default category will be omitted unless "omitDefaultCategory" is false
          stack: 'error', // only available when an error object is being logged
          message: 'context',
          callStack: 'stack', // only available when "enableCallStack" is true
        }
      }
    }
  },
  categories: {
    default: {
      appenders: ['log4json'],
      level: 'all',
      enableCallStack: true
    }
  }
});

const logger = getLogger('fancy-category');
logger.debug('string logs', 'another string log', {customProp: ['also listed', true]}, 'yet another string');

output

{
  "customProp": [
    "also listed",
    true
  ],
  "context": "string logs | another string log | yet another string",
  "@timestamp": "2021-05-10T15:25:49.130Z",
  "lvl": "DEBUG",
  "cat": "fancy-category",
  "stack": "src/log4json.js:37:8"
}