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

egg-logger

v3.5.0

Published

egg logger

Downloads

203,723

Readme

egg-logger

NPM version CI Test coverage Known Vulnerabilities npm download

Egg 的日志工具。

主要由 Logger 和 Transport 两个基类组成。

Transport 是一种写入日志的渠道,可以是终端、文件等等。

Logger 是所有日志的基类,可以进行扩展。一个 Logger 可以添加多个 Transport,只要调用一次就可以将日志写入多个地方。


Install

$ npm i egg-logger

Usage

创建一个 Logger,添加一个文件的 Transport

const Logger = require('egg-logger').Logger;
const FileTransport = require('egg-logger').FileTransport;
const ConsoleTransport = require('egg-logger').ConsoleTransport;

const logger = new Logger();
logger.set('file', new FileTransport({
  file: '/path/to/file',
  level: 'INFO',
}));
logger.set('console', new ConsoleTransport({
  level: 'DEBUG',
}));
logger.debug('debug foo'); // 不会输出到文件,只输出到终端
logger.info('info foo');
logger.warn('warn foo');
logger.error(new Error('error foo'));

开启/关闭 Transport

logger.disable('file');
logger.info('info'); // 不会输出
logger.enable('file');
logger.info('info'); // 开启后会输出

汇集日志

可以把日志复制一份到指定的日志对象,支持可选的 options.excludes 来排除对应的 tranport

logger.duplicate('error', errorLogger, { excludes: [ 'console' ] });
logger.error(new Error('print to errorLogger')); // 会多调用一次 `errorLogger.error`

重定向日志

可以将日志重定向到指定的日志对象

oneLogger.redirect('debug', debugLogger); // oneLogger 的调试日志将被 debugLogger 接管,输出过去。

重新加载文件

logger.reload(); // will end the exists write stream and create a new one.

自定义 Transport

可以自定义一个 Transport 用于输出日志,比如发送到服务器。

const urllib = require('urllib');
const Transport = require('egg-logger').Transport;

class UrllibTransport extends Transport {

  log(level, args, meta) {
    const msg = super.log(level, args, meta);
    return urllib.request('url?msg=' + msg);
  }
}

const logger = new Logger();
logger.set('remote', new UrllibTransport({
  level: 'DEBUG',
}));
logger.info('info');

console 默认打印级别设置

设置环境变量 NODE_CONSOLE_LOGGRE_LEVEL = 'INFO' | 'WARN' | 'ERROR'

License

MIT

Contributors

|fengmk2|dead-horse|popomore|atian25|semantic-release-bot|mansonchor| | :---: | :---: | :---: | :---: | :---: | :---: | |whxaxes|Jeff-Tian|waitingsong|sjfkai|congyuandong|lix059| killagu|duqingyu|AmazingCaddy|linrf|XadillaX|luckydrq

This project follows the git-contributor spec, auto updated at Wed May 08 2024 09:39:22 GMT+0800.