linglog
Easy log module with some config
Installation
$ npm install --save linglog
Usage
Initialization
Stdio
const log = 'name';
File
const log = '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; // $ [2015-12-11 12:30:12][name][info]: infolog; // $ [2015-12-11 12:30:12][name][warn]: warnlog; // $ [2015-12-11 12:30:12][name][error]: error
Debug Mode
log;log; // $ [2015-12-11 12:30:12][name][debug]: showed debug messagelog;log; // nothing
Custom Template
const log = 'name';const out = log;; // $ [TplSpecial]: special log template const err = log;; // $ [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.