linglog
v0.0.4
Published
Easy log module with some config
Downloads
657
Readme
linglog
Easy log module with some config
Installation
$ npm install --save linglog
Usage
Initialization
Stdio
const log = require('linglog')('name');
File
const log = require('linglog')('file', {
outFile: {
path: './out', // output file path
flushDuration: 1000, // buffer flush time
mode: '0666' // open file mode
},
errorFile: {
path: './err',
flushDuration: 500,
encoding: 'gbk' // file encoding
}
});
Normal
log.info('info'); // $ [2015-12-11 12:30:12][name][info]: info
log.warn('warn'); // $ [2015-12-11 12:30:12][name][warn]: warn
log.error('error'); // $ [2015-12-11 12:30:12][name][error]: error
Debug Mode
log.setDebug(true);
log.debug('show debug message'); // $ [2015-12-11 12:30:12][name][debug]: showed debug message
log.setDebug(false);
log.debug('do not show debug message'); // nothing
Custom Template
const log = require('linglog')('name');
const out = log.tplOut('[TplSpecial]: <%= output %>');
out('special log template'); // $ [TplSpecial]: special log template
const err = log.tplErr('[TplSpecial]: <%= output %>');
err('special err template'); // $ [TplSpecial]: special err template
Congiguration
flushDuration: 1000, mode: '0666', encoding: 'utf-8'
| Name | Description | Type | Default Value |
| :-------- | :-- | :--:| :--: | :--: |
| infoTpl | template for log.info
| String | '[<%= time %>][<%= name %>][info]: <%= output %>'.blue
|
| warnTpl | template for log.warn
| String | '[<%= time %>][<%= name %>][warn]: <%= output %>'.yellow
|
| errorTpl | template for log.error
| String | '[<%= time %>][<%= name %>][error]: <%= output %>'.red
|
| debugTpl | template for log.debug
| String | '[<%= time %>][<%= name %>][debug]: <%= output %>'
|
| timeFormat | moment time format in other templates | String | 'YYYY-MM-DD HH:mm:ss
|
| outFile | output file config for log.info or log.warn or log.debug
| Object | null |
| errFile | output file config for log.error
| Object | null |
| file.path | file path | String | null
|
| file.flushDuration | file flush interval | Number | 1000
|
| file.mode | file mode | String | '0666'
|
| file.encoding | file encoding | String | 'utf-8'
|
License
The MIT License (MIT)
Copyright (c) 2015
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.