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

baiji-logger

v0.0.1-alpha.6

Published

the Logger Module for Baiji

Downloads

2

Readme

baiji-logger

A logger compoment for Baiji

1. Menu

2. Installation

NodeJS version >= 10.14.2

yarn add baiji-logger
# OR
npm install baiji-logger -S

3. Usage

See details from ./test/app/index.js

// require
const baiji = require('baiji');
const path = require('path');
const baijiLogger = require('baiji-logger');
// define
const { accessLogger, error, info, debug } = baijiLogger({
  traceKey: 'serviceName',
  baseDir: path.join(__dirname, './logs'),
});
const infoLogger = info();
const errorLogger = error();
const debugLogger = debug();
// use case
const app = baiji('serviceName');
app.use(accessLogger()); // Add accessLogger for routes
// app.use(UsersCtrl); // Use controller
// Start app and listen on port 3000
app.listen(3000, () => infoLogger.info('Port : 3000'));

4. Description

Based on winstonjs/winston

4.1. classify & rotate

| classify | instance | env | transport | rotate | | -------- | ------------ | -------- | ------------------ | --------------- | | error | errorLogger | * | error.log | File | | *warning | | * | warning.log | File | | info | infoLogger | * | app.log | File | | | accessLogger | * | access.log+Console | DailyRotateFile | | *verbose | | dev/test | debug.log+Console | File | | debug | debugLogger | dev | Console | | | *silly | | dev | Console | |

  • warning/verbose/silly , not yet developed

5. Options

Description

  • | option |
  • | .filter | means option.filter
  • | -filterKeys | means options.filter.filterKeys

| param | type | default | desc | | -------------------- | --------------- | ----------------------------------------------- | ----------------------------------------------------------------------------- | | option | object | - | The option for baijiLogger | | .traceKey | string | - | The unique key for this app , be used for traceId | | .baseDir | string | - | The base direction path for logs | | .filter | * | false | Sensitive information filtering and replace | | -filterKeys | array | ['password', 'token', 'authorization'] | Filter keys array list | | -recursion | boolean | false | Is recursion | | -replaceChat | string/function | '*' | Replace chat or function | | .generateTraceId | function | ${timestamp}-${shortid}-${traceKey} | The function for generate trace id | | .errorLoggerConfig | object | - | The configuration for error logger | | -filepath | string | /${ENV}_${level}.log | Used by path.join(baseDir,filepath) | | -format | function | [${timeFormat}] [${level}] ${label} - ${json} | A string representing the moment.js date format to be used for rotating. | | -level | string | error | Log only if info.level less than or equal to this level | | -maxFiles | number | 5 | Maximum number of logs to keep. | | -maxSize | string | 10m | Maximum size of the file after which it will rotate. | | -transports | array | [ transports.Console , DailyRotateFile ] | Winston Transports | | -zippedArchive | boolean | true | A boolean to define whether or not to gzip archived log files. | | .infoLoggerConfig | object | - | The configuration for info logger | | -datePattern | string | YYYY-MM-DD | ↑ | | -filepath | string | /${level}/${ENV}_${level}_%DATE%.log | ↑ | | -format | function | [${timeFormat}] [${level}] ${label} - ${json} | ↑ | | -level | string | info | ↑ | | -maxFiles | string | 7d | ↑ | | -maxSize | string | 10m | ↑ | | -transports | array | [ transports.Console , DailyRotateFile ] | ↑ | | -zippedArchive | boolean | true | ↑ | | .accessLogger | object | - | The configuration for access logger , when requested to get the corresponding | | -body | string | ctx.req.body | Post method params | | -method | string | ctx.req.method | Http request method name | | -query | string | ctx.req.query | Get method params | | -remoteIP | string | - | Get remote ip even though proxy by nginx , see common >> getIP function | | -statusCode | string | ctx.res.statusCode | Http response statusCode | | -traceId | string | ${timestamp}-${shortid} | Trace id of full process log | | -url | string | ctx.req.originalUrl | Http request url | | -user | string | ctx.req.user | Remote user info | | .debugLoggerConfig | object | - | The configuration for debug logger | | -format | function | [${timeFormat}] [${level}] ${label} - ${json} | ↑ | | -level | string | debug | ↑ | | -transports | array | [ transports.Console ] | ↑ |

5.1. Detail Case

  • option.filter.recursion not yet developed. Is recursion. In case {"body":{"password":{"a":1}}} , if true will be {"body":{"password":{"a":"*"}}} ; else , will be {"body":{"password":"*"}} .
  • option.filter.replaceChat not yet developed. only support String type.

6. TODO list

6.1. Features

  • [x] Ensure number of log file handles < 5
  • [ ] Developing warning/silly/verbose classify
  • [x] Concurrency test
  • [ ] Improve the efficiency and concurrency of the filter function
  • [ ] Add stringify option field to use JSON.stringify(message) ; before this , judge params typeof
  • [ ] Update Options description
  • [ ] Add Kafka transport config
  • [ ] Add error email config
  • [ ] Update trace-id of req , add the key of this app
  • [ ] Add pretty message & stack show in errorLogger
  • [ ] Add method for get the trace-id and the trace-key
  • [ ] Add params to context
  • [ ] Add config for logger response data

7. Contribution Step

fork https://github.com/baijijs/logger.git
git clone <your own repository>
git branches <your own branch>
git checkout <your own branch>
yarn install -D
... something change
git cz
... step by step add commit with message
git push
pull request

8. Run Tests

Install development environment module .

yarn install -D

8.1. Unit Test

All of the logger test cases are written with Jest. They can be run with npm or yarn.

npm test
# OR
yarn test

8.2. Benchmark Test

Benchmark report log out to ./docs/benchmark.report.log .

Based on bestiejs/benchmark.js

npm run dev-filter
npm run dev-filter-false
npm run benchmark