A simple on-memory logger for Node.js / io.js app.
You can install the logger to your project with either one method:
- Install with npm:
npm install onmem-logger
- Clone the repository:
git clone https://github.com/mugifly/onmem-logger.git
// Get a logger as singleton
var logger = require('onmem-logger').getInstance();
// Insert a log & Print to stdout
logger.log('main', 'Hello world!');
logger.error('main', 'Something happend :(');
// Get a log
var logs = logger.getLogs();
for (var i = 0, l = logs.length; i < l; i++) {
var item = logs[i];
console.log(i + ' - ' + item.getTag() + ' / ' + item.getText());
}
The more examples is available on here.
- Usable very easily.
- Can be work on memory only.
- Can be integrate whole logs of the app. It also suitable for your electron app.
Get an instance of logger as singleton.
You can integrate whole logs of the app by get a logger as singleton from your each object.
Get an array of LogItem object.
Get an array as serialized logs.
Each item includes additional properties as follows. Those properties was obtained from each methods of LogItem object.
- createdTimeStr - Same as getCreatedTimeAsString() method -- e.g. "12:00:00"
- typeInitial - Same as getTypeInitial() method -- e.g. "D"; It means "debug".
- string - Same as toString() method
Insert a debug log.
- tag: {String} Tag text -- e.g. "main", "foo/bar"
- text: {String} Log text -- e.g. "Hello world"
Insert a error log. That usage is same with debug(tag, text) method.
Insert a information log. That usage is same with debug(tag, text) method.
An alias of debug(tag, text) method.
Insert a warning log. That usage is same with debug(tag, text) method.
- createdAt: {Date} Created date
- tag: {String} Tag text
- text: {String} Log text
- type: {String} Log type - 'debug', 'info', 'warn', 'error'
Get a created date as Date object.
Get a created time as a time string -- e.g. "12:00:00".
Get a tag text as String object.
Get a log text as String object.
Get a log type as String object -- e.g. "debug"
Get an initial character of a log type as String object -- e.g. "D"
Get a log item as a string. e.g. "[D 12:00:00] main / ...".
The MIT License (MIT).
Copyright (c) 2015 Masanori Ohgita.