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

@wjunt/node-logger

v1.1.3

Published

Another simple logging for Node.js

Downloads

67

Readme

@wjunt/node-logger

Another simple logging for Node.js, which implements loglevel

Strongly recommend to use TypeScript

Usage

Note: Node.js>=8 is required.

ES6 module

import logger from '@wjunt/node-logger';

logger.info('info message');

CommonJS

const logger = require('@wjunt/node-logger').default;

logger.info('info message');

Documentation

The logger API is same as loglevel. Visit loglevel documentation for more details.

Basic logging method

  • logger.trace(...msg: any[]): void;
  • logger.debug(...msg: any[]): void;
  • logger.info(...msg: any[]): void;
  • logger.warn(...msg: any[]): void;
  • logger.error(...msg: any[]): void;

Get new logger

Use getLogger to get new logger.

Example usage:

import logger, { Logger } from '@wjunt/node-logger';

const globalLogger = Logger.getLogger();

const logger1 = Logger.getLogger('new');
const logger2 = logger.getLogger('new');
const logger3 = logger1.getLogger('new');

When called with same name, getLogger method will return same instance of Logger. In this example, logger and globalLogger are same. Also logger1, logger2 and logger3.

Logger options

  • level?: number | string A valid log level.
  • noDefaultWriter?: boolean If set true, the default console writer will not be added.
  • timeFormat?: string Define how time formatted, passed to writer constructor.
  • traceFunction?: Function Base function to capture call stack, logger.trace by default.

Use logger writer

A ConsoleLoggerWriter is added by default, which write log message to stdout/stderr.

Use logger.addWriter(Writer: LoggerWriterConstructor, options?: LoggerWriterOptions): this to add customized writer.

Example usage:

import { FileLoggerWriter, Logger } from '@wjunt/node-logger';

const logger = Logger.getLogger('clean').addWriter(FileLoggerWriter);

logger.info('some message');

Here we get a logger with name 'clean', which output message to both console and file. FileLoggerWriter enables log-rotate by default. See more details at FileLoggerWriter

FileLoggerWriter

Output message to file.

Options

  • dirname?: string Where log files stored, './logs' by default.
  • rotateFormat?: false | string Format of rotated log files, 'YYYYMMDD' by default; if set false rotating will be disabled.
  • timeFormat?: string YYYY-MM-DD HH:mm:ss.SSS by default.

ConsoleLoggerWriter

Output message to console.

Options

  • timeFormat?: string HH:mm:ss.SSS by default.