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

@qfin/logger

v0.0.23

Published

The most awesome isomorphic logger for NodeJs and Browsers 😎 ❀

Downloads

3

Readme

πŸ“¦ Features

  • Support for ES6 modules
  • Is a fast JSON logger that supports pretty printing in development mode
  • Has static methods, instance methods, child loggers, log file support etc.
  • Supports both Browsers and NodeJs

πŸ’Ύ Install

Latest Release: @qfin/logger:0.0.23

npm install @qfin/logger

βš™ Module Documentation

Documentation is available at https://quantofin.github.io/logger/

Logger

The Logger class

Type: Logger

Parameters

  • options object? Configuration options for the logger.
    • options.base object An object with base properties that will be printed with every log line. (optional, default null)
    • options.name string The name of the logger. It is a good practice to give names for easier identification of modules for example. (optional, default undefined)
    • options.level string The log level. One of 'fatal', 'error', 'warn', 'info', 'debug', 'trace' or 'silent'. (optional, default 'info')
    • options.file string The location of the log file. If not given, logs will be outputted to std out/err. (optional, default undefined)
    • options.prettyPrint boolean? Whether to pretty print the logs or output json lines
    • options.redact (object | array)? The object props to redact from the output. As an array, the redact option specifies paths that should have their values redacted from any log output. Each path must be a string using a syntax which corresponds to JavaScript dot and bracket notation. If an object is supplied, three options can be specified: paths, censor and remove.
      • options.redact.paths array Required. An array of paths.
      • options.redact.censor (string | function | undefined) Censor option will overwrite keys which are to be redacted. (optional, default '[Redacted]')
      • options.redact.remove boolean Instead of censoring the value, remove both the key and the value. (optional, default false)
    • options.browser object Config for browsers only. (optional, default undefined)
      • options.browser.write (function | object)? Instead of passing log messages to console.log they can be passed to a supplied function. If write is an object, it can have methods that correspond to the levels. When a message is logged at a given level, the corresponding method is called. If a method isn't present, the logging falls back to using the console.

Examples

import Logger from '@qfin/logger';

// this creates a parent logger with name (my-app)
const logger = new Logger({ name: 'my-app', level: 'info' });

logger.info('Hello world from my awesome app!');
logger.debug('This will not be printed');

// --- somewhere else in the codebase

import Logger from '@qfin/logger';

// this creates a child logger with name (db) and it takes the log-level of the parent logger
const dbLogger = new Logger({ name: 'db' });

dbLogger.info('Successfully connected to Database: ', `${db.host}:${db.port}/${db.name}`);

// --- static logger usage

import Logger from '@qfin/logger';

// If logger is already initialized, then the parent logger reference will be used in this static call
// otherwise, a default parent logger will be initialized and then that will be used for logging
Logger.log('This is a static logger log');

log

Write a log with default or set level. The level can be set in the constructor parameter

Parameters

trace

Write a 'trace' level log, if the configured level allows for it.

Parameters

debug

Write a 'debug' level log, if the configured level allows for it.

Parameters

info

Write a 'info' level log, if the configured level allows for it.

Parameters

warn

Write a 'warn' level log, if the configured level allows for it.

Parameters

error

Write a 'error' level log, if the configured level allows for it.

Parameters

fatal

Write a 'fatal' level log, if the configured level allows for it.

Parameters

log

Static Method

Write a log with default or set level.

If the logger has already been initialized then the log level will be referred from the initialized logger, otherwise a new logger will be initialized and its default properties will be set and used.

Parameters

  • arg0 object? An object can optionally be supplied as the first parameter. Each enumerable key and value of the mergingObject is copied in to the JSON log line.

  • args ...any? args are of type varargs and each of the args can take various forms as follows:- A message string can optionally be supplied as the first parameter, or as the second parameter after supplying a mergingObject. By default, the contents of the message parameter will be merged into the JSON log line under the msg key.

    • All arguments supplied after message are serialized and interpolated according to any supplied printf-style placeholders (%s, %d, %o|%O|%j) or else concatenated together with the message string to form the final output msg value for the JSON log line.

Examples

logger.info({MIX: {IN: true}})
// {"level":30,"time":1531254555820,"MIX":{"IN":true},"v":1}

logger.info('hello world')
// {"level":30,"time":1531257112193,"msg":"hello world","v":1}

logger.info('hello', 'world')
// {"level":30,"time":1531257618044,"msg":"hello world","v":1}

logger.info('hello', {worldly: 1})
// {"level":30,"time":1531257797727,"msg":"hello {\"worldly\":1}","v":1}

logger.info('%o hello', {worldly: 1})
// {"level":30,"time":1531257826880,"msg":"{\"worldly\":1} hello","v":1}

trace

Static Method

Write a 'trace' level log, if the configured level allows for it.

If the logger has already been initialized then the log level will be referred from the initialized logger, otherwise a new logger will be initialized and its default properties will be set and used.

Parameters

debug

Static Method

Write a 'debug' level log, if the configured level allows for it.

If the logger has already been initialized then the log level will be referred from the initialized logger, otherwise a new logger will be initialized and its default properties will be set and used.

Parameters

info

Static Method

Write a 'info' level log, if the configured level allows for it.

If the logger has already been initialized then the log level will be referred from the initialized logger, otherwise a new logger will be initialized and its default properties will be set and used.

Parameters

warn

Static Method

Write a 'warn' level log, if the configured level allows for it.

If the logger has already been initialized then the log level will be referred from the initialized logger, otherwise a new logger will be initialized and its default properties will be set and used.

Parameters

error

Static Method

Write a 'error' level log, if the configured level allows for it.

If the logger has already been initialized then the log level will be referred from the initialized logger, otherwise a new logger will be initialized and its default properties will be set and used.

Parameters

fatal

Static Method

Write a 'fatal' level log, if the configured level allows for it.

If the logger has already been initialized then the log level will be referred from the initialized logger, otherwise a new logger will be initialized and its default properties will be set and used.

Parameters