Upgrading to new adapter interface
This commit is contained in:
parent
c372016397
commit
ccb5aa023f
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,7 +9,7 @@
|
|||||||
"version": "3.0.10",
|
"version": "3.0.10",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hibas123/logging": "^3.0.8",
|
"@hibas123/logging": "^3.1.0",
|
||||||
"@hibas123/utils": "^2.2.18"
|
"@hibas123/utils": "^2.2.18"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -107,9 +107,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@hibas123/logging": {
|
"node_modules/@hibas123/logging": {
|
||||||
"version": "3.0.8",
|
"version": "3.1.0",
|
||||||
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.0.8.tgz",
|
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.1.0.tgz",
|
||||||
"integrity": "sha512-Z78KRzJMPD0I22pNurx55aRW1Wo32ELn0STCwDWBJHx9pJrNBMRYf+SUHEyYSVTbS6tZ0nr9VHn8MkCdPnb1hQ==",
|
"integrity": "sha512-iUFXdkuSYcxiIChOccTC84xldwKXJ0vdNruTiVTrU07x69BL9DvuvJ6e3CBTIy2HKgT1K1q1VChTModKPEus7A==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@hibas123/utils": {
|
"node_modules/@hibas123/utils": {
|
||||||
@ -2179,9 +2179,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@hibas123/logging": {
|
"@hibas123/logging": {
|
||||||
"version": "3.0.8",
|
"version": "3.1.0",
|
||||||
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.0.8.tgz",
|
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.1.0.tgz",
|
||||||
"integrity": "sha512-Z78KRzJMPD0I22pNurx55aRW1Wo32ELn0STCwDWBJHx9pJrNBMRYf+SUHEyYSVTbS6tZ0nr9VHn8MkCdPnb1hQ=="
|
"integrity": "sha512-iUFXdkuSYcxiIChOccTC84xldwKXJ0vdNruTiVTrU07x69BL9DvuvJ6e3CBTIy2HKgT1K1q1VChTModKPEus7A=="
|
||||||
},
|
},
|
||||||
"@hibas123/utils": {
|
"@hibas123/utils": {
|
||||||
"version": "2.2.18",
|
"version": "2.2.18",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/nodelogging",
|
"name": "@hibas123/nodelogging",
|
||||||
"version": "3.0.10",
|
"version": "3.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "out/index.js",
|
"main": "out/index.js",
|
||||||
"types": "out/index.d.ts",
|
"types": "out/index.d.ts",
|
||||||
@ -32,7 +32,7 @@
|
|||||||
"typescript": "^4.2.4"
|
"typescript": "^4.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hibas123/logging": "^3.0.8",
|
"@hibas123/logging": "^3.1.0",
|
||||||
"@hibas123/utils": "^2.2.18"
|
"@hibas123/utils": "^2.2.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
import { Lock } from "@hibas123/utils";
|
import { Lock } from "@hibas123/utils";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { Adapter, Message, Formatted } from "@hibas123/logging";
|
import { Adapter, Message, Formatted, LoggingTypes } from "@hibas123/logging";
|
||||||
|
|
||||||
const MAX_FILE_SIZE = 500000000;
|
const MAX_FILE_SIZE = 500000000;
|
||||||
|
|
||||||
export class LoggingFiles implements Adapter {
|
export class LoggingFiles implements Adapter {
|
||||||
|
level = LoggingTypes.Debug;
|
||||||
|
|
||||||
file: Files;
|
file: Files;
|
||||||
constructor(private filename: string, private maxFileSize = MAX_FILE_SIZE) {}
|
constructor(private filename: string, private maxFileSize = MAX_FILE_SIZE) {}
|
||||||
|
|
||||||
|
setLevel(level: LoggingTypes) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (!this.file) {
|
if (!this.file) {
|
||||||
this.file = Files.getFile(this.filename);
|
this.file = Files.getFile(this.filename);
|
||||||
@ -41,11 +47,7 @@ const Debounce = (callback: () => void, iv = 500, max = 100) => {
|
|||||||
trigger: () => {
|
trigger: () => {
|
||||||
curr++;
|
curr++;
|
||||||
if (curr >= max) {
|
if (curr >= max) {
|
||||||
if (to) {
|
curr = 0; // not clearing timeout, since this is a very high cost operation
|
||||||
clearTimeout(to);
|
|
||||||
to = undefined;
|
|
||||||
}
|
|
||||||
curr = 0;
|
|
||||||
callback();
|
callback();
|
||||||
} else if (!to) {
|
} else if (!to) {
|
||||||
to = setTimeout(() => {
|
to = setTimeout(() => {
|
||||||
@ -55,6 +57,7 @@ const Debounce = (callback: () => void, iv = 500, max = 100) => {
|
|||||||
}, iv);
|
}, iv);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
close: () => {},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user