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

node-slogger

v3.0.0

Published

A wrapper of logger to let you print log easily.

Downloads

79

Readme

node-slogger

build status Test coverage David deps node version

NPM
A wrapper of logger package , let you wirte log easy.

Install

npm install node-slogger

How to use

The fist demo

The slogger t will print log to console with prefix of time string and log level, for example slogger.debug('debug') will print Thu Dec 15 2016 11:04:50 GMT+0800 (CST) [DEBUG] debug . Different function will be printed with different color.

const {Slogger} = require('node-slogger');
var slogger = new Slogger();

slogger.debug('debug');
slogger.info('info');
slogger.trace('trace');
slogger.warn('warn');
slogger.error('error');

Saving log to file

const path = require('path');
const fs = require('fs')
const {Slogger, LogLevel} = require('node-slogger');

const slogger = new Slogger({
    streams:{
	    [LogLevel.ERROR]: fs.createWriteStream(path.join(__dirname , './log/error.log'))
    }
});

slogger.debug('debug');//only print to console
slogger.info('info');//only print to console
slogger.trace('trace');//only print to console
slogger.warn('warn');//only print to console
slogger.error('error');//print to console and write to the file

The code of file_test.js

Printing the log to console delayed with fixed interval.

If you wanna you project run with high performance, printing to console frequently will cost a lot of cpu time. So slogger provide a feature of printing log in delay time with a fixed interval.

const {Slogger} = require('node-slogger');
const slogger = new Slogger({flushInterval:500});
slogger.debug('this is a delay log');//it will show after 500ms

Setting the log level

You can set the level of log , just use the option of level. For example we set it to warn:

const {Slogger} = require('node-slogger');
const slogger = new Slogger({level:'warn');

slogger.debug('debug');
slogger.info('info');
slogger.trace('trace');
slogger.warn('warn');
slogger.error('error');

The code of level_test.js
Only the warn adn error log will be printed as we set the level option to warn.

API

See the document of api.

Known issues

1. Not showing log on VS Code's debug panel

You should modify the launch.json and add the parameter outputCapture with the value std and parameter console with internalConsole. This is an example:

{
    "type": "node",
    "request": "launch",
    "name": "Mocha Tests",
    "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
    "args": [
        "-u",
        "tdd",
        "--timeout",
        "999999",
        "--colors",
        "${workspaceFolder}/src/test/mocha"
    ],
    "console": "internalConsole",
    "outputCapture": "std",
    "internalConsoleOptions": "openOnSessionStart"
},

Breaking changes on 3.x

  1. Singleton object are no longer the default exported and must be manually created based on the exported slogger class.
// code in 2.x and below
const slogger = require('node-slogger').init({});
// code in 3.x
const { Slogger } = require('node-slogger');
const slogger = new Slogger();
  1. Support for input file objects has been removed. Now, it is required to use a writeable stream instead.
// code in 2.x and below
const path = require('path');
const slogger = require('node-slogger').init({
    logFiles:[
        {category:'error',filename:path.join(__dirname , './log/error.log')}
    ]
});
// code in 3.x
const { Slogger } = require('node-slogger');
const fs = require('fs');
const slogger = new Slogger({
    streams:{
      [LogLevel.ERROR]: fs.createWriteStream(path.join(__dirname , './log/error.log'))
    }
});
  1. Useless Kafka feature support has been removed.
  2. Drop the support for node 12 and below.

License

MIT