README
npmlog-file2
NPM Log File 2 is a package designed to build easily your log system. For more convenience npmlog-file2 extends npmlog, so you can use it with minor changes in your application code.
Installation
npm install npmlog-file2
Basic Usage
// Call npmlog-file2 instead of npmlog
var log = require('npmlog-file2');
// Set the log level required to be displayed
log.level = 'info';
// Set the log level required to be written
log.fileLevel = 'warn';
// Set the basepath for log files
log.fileBasePath = './logs';
// Set the filename
log.fileName = 'mylog';
// write error log to mylog.log
log.info('My prefix', 'i am info'); // Displayed but not written
log.error('My prefix', 'i am error'); // Displayed and written
Output :
[Fri Feb 03 2017 18:14:44 GMT+0100 (CET)] [error] [My prefix] i am error
log.fileName
- {String}
The file name, .log
extension is automaticly added at the end of name.
log.fileBasePath
- {String}
The base path for the logs file, by default this is the logs
directory related to the executed file.
log.fileCreatePath
- {Bool}
When this feature is enabled, the path is automaticly created.
log.fileLevel
- {String}
The level to write logs. Any logs at or above this level will be written. The special level silent
will prevent anything from being logged ever.
log.fileMaxSize
- {Number}
Set the max size for the log file, when the limit is reached the file is moved and a new one is created. The size is exprimed in kilobyte
. The new file is
named mylog_1.log
or mylog_error_1.log
if you enable log.fileLevelSuffix
.
log.fileLevelSuffix
- {Bool}
This option create seperated log file for each log level. So you can have mylog_error.log
, mylog_warn.log
, mylog_info.log
etc...
About npmlog-file2
npmlog-file2 was originally based on npmlog-file written by xTuple team. I have started this fork simply to have a typed log format and other cool stuff while using npmlog package.
Bug & suggestions
If you have any suggestions or have found a bug feel free to use the tracker.