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

@zhangfuxing/logger

v2.3.6

Published

logger for nodejs

Downloads

4

Readme

logger

logger for nodejs

Install

$ npm i @zhangfuxing/logger

Node.js 12+ required (Because of use Class private fields)

options

When isTTY is false, logger will not write to terminal.

constructor

  • dir optional, Log folder path, if it is given, it will log to file
  • rotate optional, Whether cut logs by day
    • default: false
  • disableConsole optional, disable write to terminal
    • default: false

info

  • args The message to write
info(...args: any[]): void;

warn

  • args The message to write
warn(...args: any[]): void;

error

  • args The message to write
error(...args: any[]): void;

disableConsole

disable write to terminal

disableConsole(): void;

enableConsole

enable write to terminal

enableConsole(): void;

disableFile

disable write to file

disableFile(): void;

enableFile

enable write to file

enableFile(): void;

disable

disable write to file and terminal, don't care if it is currently writing to a file or terminal, but hope to restore the currently configuration later

disable(): void;

enable

restore previous log configuration: file, terminal or both

enable(): void;

Useage

console logger

const Logger = require('@zhangfuxing/logger');

const logger = new Logger();

logger.info('consoleLogger info', { name: 'zfx' });
logger.warn('consoleLogger warn', 1, 'any');
logger.error('consoleLogger error', new Error('test'));

file and console logger

const Logger = require('@zhangfuxing/logger');

const logger = new Logger({
  dir: './log'
});

logger.info('fileLogger info', 'any', { name: 'zfx' });
logger.warn('fileLogger warn', 'any', 'any');
logger.error('fileLogger error', 'any', new Error('test'), 'any');

file logger only

const Logger = require('@zhangfuxing/logger');

const logger = new Logger({
  dir: './log',
  disableConsole: true
});

logger.info('fileLogger info', 'any', { name: 'zfx' });
logger.warn('fileLogger warn', 'any', 'any');
logger.error('fileLogger error', 'any', new Error('test'), 'any');

file logger cut by day

const Logger = require('@zhangfuxing/logger');

const logger = new Logger({
  dir: './log',
  rotate: true 
});

logger.info('fileLogger info', 'any', { name: 'zfx' });
logger.warn('fileLogger warn', 'any', 'any');
logger.error('fileLogger error', 'any', new Error('test'), 'any');

disableConsole and enableConsole

const Logger = require('@zhangfuxing/logger');

const logger = new Logger();

logger.info('console enabled, you can see me');
logger.info('console will be disabled, should not see "console disabled" below ===>');
logger.disableConsole();
logger.info('console disabled');
logger.enableConsole();
logger.info('console enabled, you can see me');

or disableConsole is true when the logger is instantiated

const Logger = require('@zhangfuxing/logger');

const logger = new Logger({
  disableConsole: true
});

logger.enableConsole();
logger.info('console enabled, you can see me');
logger.info('console will be disabled, should not see any below ===>');
logger.disableConsole();
logger.info('console disabled');

disableFile and enableFile

const Logger = require('@zhangfuxing/logger');

const logger = new Logger({
  dir: './log',
  disableConsole: true
});

logger.info('file enable');
logger.info('file will be disabled, should not see "file disbaled" below ===>');
logger.disableFile();
logger.info('file disbaled');
logger.enableFile();
logger.info('file enabled, you can see me');

disable and enable

  1. fileLogger => disable => enable => fileLogger
  2. consoleLogger => disable => enable => consoleLogger
  3. fileLogger, consoleLogger => disable => enable => fileLogger, consoleLogger
const Logger = require('@zhangfuxing/logger');

const consoleLogger = new Logger();
const fileLogger = new Logger({
  dir: './log',
  disableConsole: true
});
const bothLogger = new Logger({
  dir: './log'
});

// fileLogger => disable => enable => fileLogger 
fileLogger.info('print by fileLogger, should not see "fileLogger disabled"');
fileLogger.disable();
fileLogger.info('fileLogger disabled');
fileLogger.enable();
fileLogger.info('fileLogger enabled, should see me just in file');

// consoleLogger => disable => enable => consoleLogger 
consoleLogger.info('print by consoleLogger, should not see "consoleLogger disabled"');
consoleLogger.disable();
consoleLogger.info('consoleLogger disabled');
consoleLogger.enable();
consoleLogger.info('consoleLogger enabled, should see me just in terminal');

// fileLogger, consoleLogger => disable => enable => fileLogger, consoleLogger 
bothLogger.info('print by bothLogger, should not see "bothLogger disabled"');
bothLogger.disable();
bothLogger.info('bothLogger disabled');
bothLogger.enable();
bothLogger.info('bothLogger enabled, should see me both in file and terminal');

Test

$ npm test

More test file in the test folder.

Screenshots

consoleLogger
consoleLogger

fileLogger
fileLogger

cut logs by day
CutByDay

More screenshots in the screenshots folder.