JSON Logger
Description
Streaming logger in JSON format with rotator streaming supported
Quick Start
Install with NPM:
npm install my-jslogger --save
Use in your code:
// Import dependenciesvar JSLogger = ; // Create a new loggervar logger = JSLoggerLOGLEVELinfo;
Pipe the log output to any writable stream or built-in rotator stream:
// Make the logs your program's outputlogger; // Write the logs to a filelogger;
Pipe the log output to a built-in rotator stream:
// Write the logs to a file rotatorvar RotatorStream = RotatorStream; var stream = ; logger;
Customize Log Rotator Stream
[new] RotatorStream(filename, options)
Create a new log rotator stream
Default Options
const OPTIONS_DEFAULT = size: '10M' // rotate every 10 MegaBytes written maxFiles: 10 // number of rotated files interval: '1d' // rotate daily compress: 'gzip' // compress rotated files;
Customizable options
filename {String}
File destination
options {Object}
- compress: {True} (default: null) Enable compression for rotated file.
- interval: {String} (default: null) Specifies the time interval to rotate the file.
- maxFiles: {Integer} (default: null) Specifies the maximum number of rotated files to keep.
- rotate: {Integer} (default: null) Enables the classical UNIX logrotate behaviour.
- size: {String} (default: null) Specifies the file size to rotate the file.
size
Accepts a positive integer followed by one of these possible letters:
- B: Bites
- K: KiloBites
- M: MegaBytes
- G: GigaBytes
size: '300B' // rotates the file when size exceeds 300 Bytes // useful for tests
size: '300K' // rotates the file when size exceeds 300 KiloBytes
size: '100M' // rotates the file when size exceeds 100 MegaBytes
size: '1G' // rotates the file when size exceeds a GigaByte
interval
Accepts a positive integer followed by one of these possible letters:
- s: seconds. Accepts integer divider of 60.
- m: minutes. Accepts integer divider of 60.
- h: hours. Accepts integer divider of 24.
- d: days
interval: '5s' // rotates at seconds 0, 5, 10, 15 and so on // useful for tests
interval: '5m' // rotates at minutes 0, 5, 10, 15 and so on
interval: '2h' // rotates at midnight, 02:00, 04:00 and so on
interval: '1d' // rotates at every midnight
License
MIT
Copyright (c) 2017 dxhome
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.