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

toger

v1.2.4

Published

a tiny logger for node.

Downloads

1

Readme

toger

一个小巧精致的 nodejs 日志模块

Travis Coverage Status David npm (scoped) node (scoped) GitHub license

安装

$ yarn add toger # 推荐
# 或者
$ npm i -S toger

使用

import toger from 'toger';
// 或者
// const { toger } = require('toger');

const logger = toger();

logger.trace('你好!'); // [2018-06-01 10:00:00] TRACE 你好!
logger.debug('你好!'); // [2018-06-01 10:00:00] DEBUG 你好!
logger.info('你好!');  // [2018-06-01 10:00:00] INFO 你好!
logger.warn('你好!');  // [2018-06-01 10:00:00] WARN 你好!
logger.error('你好!'); // [2018-06-01 10:00:00] ERROR 你好!
logger.fatal('你好!'); // [2018-06-01 10:00:00] FATAL 你好!

这是默认日志级别。
输入的时候会有智能提示哦。

设置日志级别

import toger from 'toger';

const logger = toger({
  level: 'warn',
});

logger.trace('你好!');
logger.debug('你好!');
logger.info('你好!');
logger.warn('你好!');
logger.error('你好!');
logger.fatal('你好!');

这样只会输出 warn, error, fatal 三个级别的日志。

自定义日志级别

import toger from 'toger';

const logger = toger({
  levels: ['http', 'api', 'mysql', 'redis'],
});

logger.http('http 日志');
logger.api('api 日志');
logger.mysql('mysql 日志');
logger.redis('redis 日志');

这样的日志是不是很方便呢。

输出到文件

import toger from 'toger';

const logger = toger({
  stream: true,
});

logger.trace('你好!');
logger.debug('你好!');
logger.info('你好!');
logger.warn('你好!');
logger.error('你好!');
logger.fatal('你好!');

默认输出到当前目录的 logs 目录下,如果 logs 目录不存在则报错。

const logger = toger({
  stream: {
    dir: 'logs', // 日志目录
    filename: '{level}.log', // 输出的文件名
    cache: 1000, // 开启缓存,每 1s 写入一次。
  },
});

这是 stream 参数默认配置。

const { toger } = require('toger');

const logger = toger({
  levels: ['http', 'api', 'mysql', 'redis'],
  stream: ,
});

logger.http('http 日志');
logger.api('api 日志');
logger.mysql('mysql 日志');
logger.redis('redis 日志');

当然也可以结合 levels 输出到文件。

API

toger(options)

options

| 参数 | 类型 | 可选 | 默认值 | 描述 | | :-- | :-- | :--: | :-- | :-- | | level | string | 是 | 'all' | 输出级别,all全部输出,off关闭日志 | | levels | string[] | 是 | ['trace', 'debug', 'info', 'warn', 'error', 'fatal'] | 日志级别 | | json | boolean | 是 | false | 输出JSON格式 | | stamp | boolean | 是 | false | 日期输出为时间戳 | | stream | boolean/object | 是 | null | 输出到文件,设为 true 使用默认配置 |

options.stream

| 参数 | 类型 | 可选 | 默认值 | 描述 | | :-- | :-- | :--: | :-- | :-- | | dir | string | 是 | 'logs' | 日志目录 | | filename | string | 是 | '{level}.log' | 文件名 | | cache | number | 是 | 1000 | 缓存刷新时间 0是关闭 | | mode | number | 是 | 0o666 | linux 文件模式 | | error | function | 是 | function(){} | 文件错误回调事件 |

License

MIT