Compare commits

..

No commits in common. "0dbd8e9c40131a3a45172c18e74e1b3d08a9e801" and "2aaee1be8963bf05994de675ab71f21eadd2988c" have entirely different histories.

4 changed files with 56 additions and 96 deletions

69
package-lock.json generated
View File

@ -1,26 +1,26 @@
{
"name": "@hibas123/nodelogging",
"version": "2.0.0",
"version": "1.6.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@hibas123/logging": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@hibas123/logging/-/logging-2.0.0.tgz",
"integrity": "sha512-v4e7xiXGvAKpq6nxLA2TVoEy/DTT7DZkqEKh8eZ1XiAQAJh0PnmF1GP/TdHWvDTPMG/U8kMHArrGllVxM6xtkg==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@hibas123/logging/-/logging-1.1.0.tgz",
"integrity": "sha512-EaDyvvWDD+SikLgP6WTvTCR6Sk9Kp2BZkDbUk0Rz4pF2B4dGyO8yRI8qhBEtjbMXGqedeM5mQDGgvY5QUDevVg==",
"requires": {
"@hibas123/utils": "^2.0.5"
"@hibas123/utils": "^2.0.2"
}
},
"@hibas123/utils": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@hibas123/utils/-/utils-2.0.5.tgz",
"integrity": "sha512-LI1Xw0QArpm0JqCUmuxRG7dgmjvyLPmJehcNRqHrWuCwmDRoPFe0PwmZsp8/saz6pCL2A4u0utVHWG2PG4lSyg=="
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@hibas123/utils/-/utils-2.0.2.tgz",
"integrity": "sha512-5yrpuuUv0YlL2BixiTQLta4EmPLMNZ9Waorymu6dbERiSIcBxDs8mcJDUDW7CGiewpHHQUMsqLycLUYPDx0LWw=="
},
"@types/node": {
"version": "11.13.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.0.tgz",
"integrity": "sha512-rx29MMkRdVmzunmiA4lzBYJNnXsW/PhG4kMBy2ATsYaDjGGR75dCFEVVROKpNwlVdcUX3xxlghKQOeDPBJobng==",
"version": "11.11.7",
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.7.tgz",
"integrity": "sha512-bHbRcyD6XpXVLg42QYaQCjvDXaCFkvb3WbCIxSDmhGbJYVroxvYzekk9QGg1beeIawfvSLkdZpP0h7jxE4ihnA==",
"dev": true
},
"abbrev": {
@ -805,8 +805,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
@ -827,14 +826,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -849,20 +846,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -979,8 +973,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -992,7 +985,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -1007,7 +999,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -1015,14 +1006,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -1041,7 +1030,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -1122,8 +1110,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -1135,7 +1122,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -1221,8 +1207,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -1258,7 +1243,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -1278,7 +1262,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -1322,14 +1305,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
@ -2786,9 +2767,9 @@
"dev": true
},
"typescript": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.1.tgz",
"integrity": "sha512-3NSMb2VzDQm8oBTLH6Nj55VVtUEpe/rgkIzMir0qVoLyjDZlnMBva0U6vDiV3IH+sl/Yu6oP5QwsAQtHPmDd2Q==",
"version": "3.3.4000",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.4000.tgz",
"integrity": "sha512-jjOcCZvpkl2+z7JFn0yBOoLQyLoIkNZAs/fYJkUG6VKy6zLPHJGfQJYFHzibB6GJaF/8QrcECtlQ5cpvRHSMEA==",
"dev": true
},
"undefsafe": {

View File

@ -1,6 +1,6 @@
{
"name": "@hibas123/nodelogging",
"version": "2.0.1",
"version": "1.7.0",
"description": "",
"main": "out/index.js",
"types": "out/index.d.ts",
@ -20,13 +20,13 @@
"author": "Fabian Stamm",
"license": "MIT",
"devDependencies": {
"@types/node": "^11.13.0",
"@types/node": "^11.11.7",
"concurrently": "^4.1.0",
"nodemon": "^1.17.4",
"typescript": "^3.4.1"
"typescript": "^3.3.4000"
},
"dependencies": {
"@hibas123/logging": "^2.0.0",
"@hibas123/utils": "^2.0.5"
"@hibas123/logging": "^1.1.0",
"@hibas123/utils": "^2.0.2"
}
}

View File

@ -4,18 +4,18 @@ import * as path from "path";
import { Adapter, Message, LoggingTypes } from "@hibas123/logging";
const MAX_FILE_SIZE = 500000000;
const maxFileSize = 500000000;
export class LoggingFiles implements Adapter {
file: Files;
constructor(filename: string, private error = false, private maxFileSize = MAX_FILE_SIZE) {
constructor(filename: string, private error = false) {
this.file = Files.getFile(filename);
}
init(observable: ObservableInterface<Message>) {
observable.subscribe(this.onMessage.bind(this));
return this.file.init(this.maxFileSize);
return this.file.init();
}
flush(sync: boolean) {
@ -26,21 +26,20 @@ export class LoggingFiles implements Adapter {
// Just ignore all non error messages, if this.error is set
if (this.error && message.type !== LoggingTypes.Error)
return;
let txt = message.text.formatted.join("\n") + "\n";
txt = txt.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
let txt = message.text.formatted.map(fmt => fmt.map(f => f.text).join("") + "\n").join("");
let index = txt.indexOf("\x1b");
while (index >= 0) {
txt = txt.substring(0, index) + txt.substring(index + 5, txt.length);
index = txt.indexOf("\x1b");
}
let msg = Buffer.from(txt);
this.file.write(msg);
}
close() {
this.file.close();
}
}
export class Files {
private open = 0;
private static files = new Map<string, Files>();
static getFile(filename: string): Files {
filename = path.resolve(filename);
@ -49,11 +48,9 @@ export class Files {
file = new Files(filename);
this.files.set(filename, file);
}
file.open++;
return file;
}
private maxFileSize = MAX_FILE_SIZE;
private size: number = 0;
private stream: fs.WriteStream = undefined;
private lock = new Lock();
@ -62,11 +59,10 @@ export class Files {
private constructor(private file: string) { }
public async init(maxFileSize: number) {
public async init() {
if (this.initialized)
return;
let lock = await this.lock.getLock();
this.maxFileSize == maxFileSize;
await this.initializeFile()
this.initialized = true;
lock.release();
@ -88,7 +84,7 @@ export class Files {
let size = 0;
if (await fsExists(this.file)) {
let stats = await fsStat(this.file);
if (new_file || stats.size >= this.maxFileSize) {
if (new_file || stats.size >= maxFileSize) {
if (await fsExists(this.file + ".old"))
await fsUnlink(this.file + ".old");
await fsMove(this.file, this.file + ".old")
@ -118,14 +114,6 @@ export class Files {
lock.release();
}
public async close() {
await this.flush(false);
this.open--;
if (this.open <= 0) {
this.stream.close()
Files.files.delete(this.file);
}
}
public flush(sync: boolean) {
if (sync) {
// if sync flush, the process most likely is in failstate, so checkQueue stopped its work.
@ -144,7 +132,7 @@ export class Files {
private async write_to_file(data: Buffer) {
try {
if (data.byteLength < this.maxFileSize && this.size + data.byteLength > this.maxFileSize) {
if (data.byteLength < maxFileSize && this.size + data.byteLength > maxFileSize) {
await this.initializeFile(true)
}
this.size += data.byteLength;
@ -161,10 +149,6 @@ export class Files {
this.queue.push(data);
this.checkQueue()
}
public dispose() {
}
}
function fsUnlink(path) {

View File

@ -6,17 +6,13 @@ import { LoggingBase as LoggingBaseOriginal, LoggingBaseOptions } from "@hibas12
export interface LoggingOptions extends LoggingBaseOptions {
files: boolean | {
/**
* Filename/path of the logfile. Skip if generated with name.
*
* If not wanted pass null
* Filename/path of the logfile. Skip if generated with name
*/
logfile?: string | null;
logfile: string;
/**
* Filename/path of the logfile. Skip if generated with name.
*
* If not wanted pass null
* Filename/path of the logfile. Skip if generated with name
*/
errorfile?: string | null;
errorfile: string;
}
}
@ -30,23 +26,22 @@ export class LoggingBase extends LoggingBaseOriginal {
if (typeof config !== "string" && typeof config.files === "object") {
logfile = config.files.logfile;
errorfile = config.files.errorfile;
} else {
let name = this.name ? "." + this.name : "";
logfile = `./logs/all${name}.log`;
errorfile = `./logs/error${name}.log`;
}
let name = this.name ? "." + this.name : "";
if (!logfile && logfile !== null)
logfile = `./logs/all${name}.log`;
if (!errorfile && errorfile !== null)
errorfile = `./logs/error${name}.log`;
if (logfile)
if (logfile) {
this.addAdapter(new LoggingFiles(logfile));
}
if (errorfile)
if (errorfile) {
this.addAdapter(new LoggingFiles(errorfile, true));
}
}
}
}
export let Logging: LoggingBase = undefined;
if (process.env.LOGGING_NO_DEFAULT !== "true") {