@szhou/beauty-logger
v5.3.12
Published
A beautiful logger system for both nodejs and browser
Downloads
8
Maintainers
Readme
beauty-logger
[ENGLISH] | 中文
A beautiful logger system for both nodejs and browser
Tip
For browser logger, it's better to use logger-for-cannot-duplicate
Usage
const path = require('path');
const Logger = require('beauty-logger');
const logger1 = new Logger({
logFilePath: path.join(__dirname, './server.log'),
});
const logger2 = new Logger({
//max size of per log file, default: 10MB
logFileSize: 1024 * 1024 * 5,
logFilePath: {
//log file name, default: as follows
info: path.join(__dirname, './info.log'),
warn: path.join(__dirname, './warn.log'),
error: path.join(__dirname, './error.log'),
},
//enable data type warn, default: false
dataTypeWarn: true,
//disable print log in console, default: false
productionModel: false,
//only print log in console, default: false
onlyPrintInConsole: false,
//execute other beauty logger instance at the same time,default:[]
otherBeautyLoggerInstances: [],
//execute callback when logging, default: null
//level: log level
//data: log content
//pid: process pid
//filePath: execute log function filename
//content: pure log content, without time and pid and etc.
callback: (level, data, pid, filePath, content) => void,
//count package usage to upload
uploadPackageInfoUrl: ""
});
logger1.info('logger1', 'beauty-logger'); // [2021-12-21 16:30:18.998] [INFO] [charms-Mac-Pro.local] [3400] [lib/beauty-logger.ts:323] "logger1" [ext] "beauty-logger"
logger2.info('logger2', 'beauty-logger'); // [2021-12-21 16:30:18.998] [INFO] [charms-Mac-Pro.local] [3400] [lib/beauty-logger.ts:323] "logger2" [ext] "beauty-logger"
Apis
- logger.debug
- logger.info
- logger.warn
- logger.error
- logger.log
Test
npm run test
Functions
Support user define the slice of log file size and log file path.
Only logger.debug doesn't log to file, all of them can be print in console.
Only identify 999 levels in input value which contains object or array.
Support to print part of req and res(big object) in nodejs
Data type includes Number, String, Undefined, Null, Boolean, Object, Array, Function, Error, Set, Map and Symbol can be support stringify. If something can't be stringify, it will be print data type, such as DOM element, it will print '[object HTMLDivElement]'
Although we support print Function, Set, Map and Symbol directly, we still don't recommend to print it without any transfer, and it will give a warn to remind you if you set dataTypeWarn to be true.
Enable productionModel will not print log to console, it will be fast for program in production environment.
In default, it will log file by log level and it will log into multiple different kinds of files, if you specify logFilePath as a path string, beauty-logger will print all logs to one file.
Support new multiple beauty-logger instance to log different files.
All of logger method support Promise chain call
Reserve data type which is in console, only stringify data which will be written to file.
Only support logger.debug, logger.info, logger.warn, logger.error and logger.log
Support nodejs at least 6.x
support more beauty logger working at the same time and print which file execute it correctly.
execute callback when logging