nya-logger
v0.1.4-alpha
Published
Another simple logger for Web & Node
Downloads
8
Readme
#NyaLogger
Description
Another simple logger for Web & Node.
It's a wrap of console.xxx
, but added some useful feature
This module is still in development, DO NOT user in production environment.
Usage
Install it by npm i nya-logger
or download a zip file.
Then:
const NyaLogger = require('nya-logger');
let logger = new NyaLogger(options); // Options is not required parameter
logger.setLevel(NyaLogger.Level.LOG); // This is optional, default is INFO
logger.trace('sample');
logger.log('sample');
logger.info('sample');
logger.warn('sample');
logger.error('sample');
logger.fatal('sample');
logger.getLog(); // Get all log from storage, return empty array if enableStorage is false
Available Options
Parameters
|Name|Default|Description| |----|-------|-----------| |showTime|True|Add time before log content, like "[2016-01-01] Sample Message"| |logLevel|Level.INFO|All level in NyaLogger.Level is valid, lower than this level will not be display |showLevel|False|Add level before log content, like "[2016-01-01] [Warn] Sample Message" |timeFormat|YYYY-MM-DD HH:mm:ss|Available if showTime is enabled, detail see next table |enableStorage|False|Save recent log to storage |storageSize|100|Max log number for log storage
{
showTime: true,
logLevel: Level.LOG,
showLevel: true,
timeFormat: 'YYYY-MM-DD HH:mm:ss',
enableStorage: false,
storageSize: 100
}
Time Format
|Token|Output|Description| |-----|------|-----------| |YYYY|2016|Full year| |YY|16|Year| |MM|02|Full month| |M|2|Month| |DD|03|Ful day |D|3|Day |HH|05|Full hours |H|5|Hours |mm|08|Full minutes |m|8|Minutes |ss|01|Full seconds |s|1|Seconds |SS|07|Full milliseconds |S|7|Milliseconds
TODO
- [x] Basic feature
- [x] Custom time format
- [ ] Add a 'stack' for view log by level
- [ ] Allow write to file in Node.JS environment
- [ ] Add mocha test
- [ ] Push to server feature
Contributors
Fell free to create a Pull Request, or submit issue.
License
GNU Public License Version 2