+29
-23
| 'use strict'; | ||
| const fs = require('fs'); | ||
| const { EventEmitter } = require('events'); | ||
| const events = require('events'); | ||
| const common = require('@metarhia/common'); | ||
@@ -63,3 +63,3 @@ const { WritableFileStream } = require('metastreams'); | ||
| class Logger extends EventEmitter { | ||
| class Logger extends events.EventEmitter { | ||
| // path <string> log directory | ||
@@ -95,6 +95,6 @@ // workerId <string> workwr process or thread id | ||
| this.toStdout = logTypes(toStdout); | ||
| this.open(); | ||
| return this.open(); | ||
| } | ||
| open() { | ||
| async open() { | ||
| if (this.active) return; | ||
@@ -129,5 +129,7 @@ this.active = true; | ||
| }); | ||
| await events.once(this, 'open'); | ||
| return this; | ||
| } | ||
| close() { | ||
| async close() { | ||
| if (!this.active) return; | ||
@@ -141,20 +143,24 @@ if (!this.fsEnabled) { | ||
| if (!stream || stream.destroyed || stream.closed) return; | ||
| this.flush(err => { | ||
| if (err) { | ||
| process.stdout.write(`${err.stack}\n`); | ||
| this.emit('error', err); | ||
| return; | ||
| } | ||
| this.active = false; | ||
| stream.end(() => { | ||
| clearInterval(this.flushTimer); | ||
| clearTimeout(this.reopenTimer); | ||
| this.flushTimer = null; | ||
| this.reopenTimer = null; | ||
| const fileName = this.file; | ||
| this.emit('close'); | ||
| fs.stat(fileName, (err, stats) => { | ||
| if (err) return; | ||
| if (stats.size > 0) return; | ||
| fs.unlink(this.file, () => {}); | ||
| return new Promise((resolve, reject) => { | ||
| this.flush(err => { | ||
| if (err) { | ||
| process.stdout.write(`${err.stack}\n`); | ||
| this.emit('error', err); | ||
| reject(err); | ||
| return; | ||
| } | ||
| this.active = false; | ||
| stream.end(() => { | ||
| clearInterval(this.flushTimer); | ||
| clearTimeout(this.reopenTimer); | ||
| this.flushTimer = null; | ||
| this.reopenTimer = null; | ||
| const fileName = this.file; | ||
| this.emit('close'); | ||
| resolve(); | ||
| fs.stat(fileName, (err, stats) => { | ||
| if (err) return; | ||
| if (stats.size > 0) return; | ||
| fs.unlink(this.file, () => {}); | ||
| }); | ||
| }); | ||
@@ -161,0 +167,0 @@ }); |
+4
-4
| { | ||
| "name": "metalog", | ||
| "version": "2.0.1", | ||
| "version": "2.1.0", | ||
| "author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -47,5 +47,5 @@ "description": "Logger for Metarhia", | ||
| "devDependencies": { | ||
| "eslint": "^6.8.0", | ||
| "eslint-config-prettier": "^6.10.1", | ||
| "eslint-plugin-prettier": "^3.1.2", | ||
| "eslint": "^7.1.0", | ||
| "eslint-config-prettier": "^6.11.0", | ||
| "eslint-plugin-prettier": "^3.1.3", | ||
| "metatests": "^0.7.1", | ||
@@ -52,0 +52,0 @@ "prettier": "^1.19.1" |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
10653
2.01%258
2.38%