Socket
Socket
Sign inDemoInstall

baiji-logger

Package Overview
Dependencies
48
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    baiji-logger

the Logger Module for Baiji


Version published
Weekly downloads
5
Maintainers
1
Install size
7.80 MB
Created
Weekly downloads
 

Readme

Source

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

classifyinstanceenvtransportrotate
errorerrorLogger*error.logFile
*warning*warning.logFile
infoinfoLogger*app.logFile
accessLogger*access.log+ConsoleDailyRotateFile
*verbosedev/testdebug.log+ConsoleFile
debugdebugLoggerdevConsole
*sillydevConsole
  • warning/verbose/silly , not yet developed

5. Options

Description

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

paramtypedefaultdesc
optionobject-The option for baijiLogger
.traceKeystring-The unique key for this app , be used for traceId
.baseDirstring-The base direction path for logs
.filter*falseSensitive information filtering and replace
-filterKeysarray['password', 'token', 'authorization']Filter keys array list
-recursionbooleanfalseIs recursion
-replaceChatstring/function'*'Replace chat or function
.generateTraceIdfunction${timestamp}-${shortid}-${traceKey}The function for generate trace id
.errorLoggerConfigobject-The configuration for error logger
-filepathstring/${ENV}_${level}.logUsed by path.join(baseDir,filepath)
-formatfunction[${timeFormat}] [${level}] ${label} - ${json}A string representing the moment.js date format to be used for rotating.
-levelstringerrorLog only if info.level less than or equal to this level
-maxFilesnumber5Maximum number of logs to keep.
-maxSizestring10mMaximum size of the file after which it will rotate.
-transportsarray[ transports.Console , DailyRotateFile ]Winston Transports
-zippedArchivebooleantrueA boolean to define whether or not to gzip archived log files.
.infoLoggerConfigobject-The configuration for info logger
-datePatternstringYYYY-MM-DD
-filepathstring/${level}/${ENV}_${level}_%DATE%.log
-formatfunction[${timeFormat}] [${level}] ${label} - ${json}
-levelstringinfo
-maxFilesstring7d
-maxSizestring10m
-transportsarray[ transports.Console , DailyRotateFile ]
-zippedArchivebooleantrue
.accessLoggerobject-The configuration for access logger , when requested to get the corresponding
-bodystringctx.req.bodyPost method params
-methodstringctx.req.methodHttp request method name
-querystringctx.req.queryGet method params
-remoteIPstring-Get remote ip even though proxy by nginx , see common >> getIP function
-statusCodestringctx.res.statusCodeHttp response statusCode
-traceIdstring${timestamp}-${shortid}Trace id of full process log
-urlstringctx.req.originalUrlHttp request url
-userstringctx.req.userRemote user info
.debugLoggerConfigobject-The configuration for debug logger
-formatfunction[${timeFormat}] [${level}] ${label} - ${json}
-levelstringdebug
-transportsarray[ 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

  • Ensure number of log file handles < 5
  • Developing warning/silly/verbose classify
  • 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

Keywords

FAQs

Last updated on 03 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc