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

rebas-logger

v0.1.0

Published

A log module on NodeJS, depends on "log4js" package. by Coffee-script

Downloads

762

Readme

rebas-logger

一个Node层的Log模块,依赖Log4js。可以按照时间/文件尺寸等方式分割日志文件。

Installation

下载模块

git clone https://github.com/ecomfe/rebas-logger.git
cd rebas-logger
git checkout 'master'
npm install

API

默认情况下会使用一个category为_log_的按时间拆分的日志作为输出。

Methods

setConfig(filename)

设置配置文件,以增量添加的方式增加配置项

  • filename {string=} 设置全局配置文件路径

getLogger(options)

获得不同类型Logger实例

  • options {Object=|string=} options 如果为string则为errorLevel, 默认category为内置'log'
    • category {string=} log分类 可与配置文件中“appenders.category”对应
    • errorLevel {errorLevel=} 可log的error_level 可与配置文件中“levels”对应
var log = require('rebas-logger');

// 如果无配置文件,则不需要调用
log.setConfig('config.json');

var logger = logger.getLogger();

logger.trace('message...');
logger.debug('message...');
logger.info('message...');
logger.warn('message...');
logger.error('message...');
logger.fatal('message...');

expressLogger()

通过express.use()加载log模块

var express = require('express');
var logger = require('rebas-logger');

app = express();
// 如果无配置文件,则不需要调用
logger.setConfig('config.json');

app.use(logger.expressLogger());

配置文件详解

JSON格式,基于log4js的配置文件,做了字段扩展。

JSON不支持注释,如果使用以下JSON,请将注释自行去掉。

{
  "appenders": [ // 添加日志输出的类型
    {
      "type": "dateFile", // 按日期分割
      "filename": "logA", // 文件名前缀,与pattern组成文件全称
      "pattern": "-yyyy-MM-dd hh.log", // 规则匹配
      "alwaysIncludePattern": true, // 文件名是否包含pattern部分
      "category": "express" // log类型 在getLogger中指定的category
    },
    {
      "type": "console", // 控制台输出
      "layout": {
        "type": "pattern",
        "pattern": "[%d] [%p] %c - %m" // %r - time in toLocaleTimeString format
                                       // %p - log level
                                       // %c - log category
                                       // %h - hostname
                                       // %m - log data
                                       // %% - %
                                       // %n - newline
                                       // %x{<tokenname>} - add dynamic tokens to your log. Tokens are specified in the tokens parameter
                                       // %[ and %] - define a colored bloc
      }
    },
    {
      "type": "file",
      "absolute": true, // 是否使用绝对路径
      "filename": "/absolute/path/to/log_file.log",
      "maxLogSize": 20480, // 文件最大size 超过后分割. 单位:byte
      "category": "absolute-logger"          
    }
  ],

  "levels": { // 配置log级别。key为对应的category,value为可显示的级别
    "[all]": "TRACE",
    "express": "ERROR",
    "app": "TRACE"
  },
  replaceConsole: true // 替换默认console
  "cwd": "./logs" // 日志文件路径
}