Comparing version 1.0.4 to 1.0.5
@@ -11,3 +11,11 @@ 'use strict'; | ||
const LOG_TYPES = [ | ||
'system', 'fatal', 'error', 'warn', 'info', 'debug', 'access', 'slow', 'db' | ||
'system', | ||
'fatal', | ||
'error', | ||
'warn', | ||
'info', | ||
'debug', | ||
'access', | ||
'slow', | ||
'db', | ||
]; | ||
@@ -58,3 +66,2 @@ | ||
class ApplicationLogger { | ||
// logger <Logger> | ||
@@ -105,7 +112,5 @@ // application <string> name | ||
} | ||
} | ||
class Logger extends events.EventEmitter { | ||
// path <string> log directory | ||
@@ -206,3 +211,9 @@ // node <string> nodeId | ||
const date = new Date( | ||
now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 0, 0, 0, 0 | ||
now.getUTCFullYear(), | ||
now.getUTCMonth(), | ||
now.getUTCDate(), | ||
0, | ||
0, | ||
0, | ||
0 | ||
); | ||
@@ -237,3 +248,3 @@ const time = date.getTime(); | ||
const time = date.toISOString(); | ||
const multiline = (/[\n\r]/g).test(message); | ||
const multiline = /[\n\r]/g.test(message); | ||
const line = multiline ? lineStack(message) : message; | ||
@@ -247,12 +258,22 @@ const data = `${time} [${type}] ${this.node}/${application} ${line}\n`; | ||
flush(callback) { | ||
if (!this.active || this.lock || !this.buffer.length) { | ||
if (callback) callback(new Error('Can\'t flush log buffer')); | ||
if (this.lock) { | ||
if (callback) this.once('unlocked', callback); | ||
return; | ||
} | ||
if (this.buffer.length === 0) { | ||
if (callback) callback(); | ||
return; | ||
} | ||
if (!this.active) { | ||
if (callback) | ||
callback(new Error('Cannot flush log buffer: logger is not opened')); | ||
return; | ||
} | ||
this.lock = true; | ||
const buffer = Buffer.concat(this.buffer); | ||
this.buffer.length = 0; | ||
this.stream.write(buffer, err => { | ||
this.stream.write(buffer, () => { | ||
this.lock = false; | ||
if (callback) callback(err); | ||
this.emit('unlocked'); | ||
if (callback) callback(); | ||
}); | ||
@@ -264,5 +285,4 @@ } | ||
} | ||
} | ||
module.exports = args => new Logger(args); |
{ | ||
"name": "metalog", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -23,3 +23,4 @@ "description": "Meta Logger for Metarhia", | ||
"test": "eslint . && metatests test/", | ||
"lint": "eslint ." | ||
"lint": "eslint . && prettier -c \"**/*.js\" \"**/*.json\" \"**/*.md\" \".*rc\" \"**/*.yml\"", | ||
"fmt": "prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \".*rc\" \"**/*.yml\"" | ||
}, | ||
@@ -35,4 +36,7 @@ "engines": { | ||
"eslint": "^5.12.0", | ||
"metatests": "^0.4.0" | ||
"eslint-config-prettier": "^3.5.0", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"metatests": "^0.4.0", | ||
"prettier": "1.16.x" | ||
} | ||
} |
@@ -17,3 +17,3 @@ # Meta Logger for Metarhia | ||
- Timur Shemsedinov (marcusaurelius) <timur.shemsedinov@gmail.com> | ||
- See github for full [contributors list](https://github.com/metarhia/metalog/graphs/contributors) | ||
- Timur Shemsedinov (marcusaurelius) <timur.shemsedinov@gmail.com> | ||
- See github for full [contributors list](https://github.com/metarhia/metalog/graphs/contributors) |
@@ -11,3 +11,3 @@ 'use strict'; | ||
writeBuffer: 64 * 1024, | ||
keepDays: 5 | ||
keepDays: 5, | ||
}); | ||
@@ -33,2 +33,1 @@ | ||
logger.close(); | ||
@@ -6,10 +6,11 @@ 'use strict'; | ||
const createLogger = () => metalog({ | ||
path: './log', | ||
node: 'S1N1', | ||
writeInterval: 3000, | ||
writeBuffer: 64 * 1024, | ||
keepDays: 5, | ||
toStdout: [] | ||
}).bind('app1'); | ||
const createLogger = () => | ||
metalog({ | ||
path: './log', | ||
node: 'S1N1', | ||
writeInterval: 3000, | ||
writeBuffer: 64 * 1024, | ||
keepDays: 5, | ||
toStdout: [], | ||
}).bind('app1'); | ||
@@ -16,0 +17,0 @@ const logger1 = createLogger(); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22225
11
380
5
2