mirror of
https://git.stamm.me/OpenServer/NodeLogging.git
synced 2024-11-21 23:19:23 +00:00
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",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@hibas123/logging": "^3.0.8",
|
||||
"@hibas123/logging": "^3.1.0",
|
||||
"@hibas123/utils": "^2.2.18"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -107,9 +107,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@hibas123/logging": {
|
||||
"version": "3.0.8",
|
||||
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.0.8.tgz",
|
||||
"integrity": "sha512-Z78KRzJMPD0I22pNurx55aRW1Wo32ELn0STCwDWBJHx9pJrNBMRYf+SUHEyYSVTbS6tZ0nr9VHn8MkCdPnb1hQ==",
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.1.0.tgz",
|
||||
"integrity": "sha512-iUFXdkuSYcxiIChOccTC84xldwKXJ0vdNruTiVTrU07x69BL9DvuvJ6e3CBTIy2HKgT1K1q1VChTModKPEus7A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@hibas123/utils": {
|
||||
@ -2179,9 +2179,9 @@
|
||||
}
|
||||
},
|
||||
"@hibas123/logging": {
|
||||
"version": "3.0.8",
|
||||
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.0.8.tgz",
|
||||
"integrity": "sha512-Z78KRzJMPD0I22pNurx55aRW1Wo32ELn0STCwDWBJHx9pJrNBMRYf+SUHEyYSVTbS6tZ0nr9VHn8MkCdPnb1hQ=="
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://npm.hibas123.de/@hibas123%2flogging/-/logging-3.1.0.tgz",
|
||||
"integrity": "sha512-iUFXdkuSYcxiIChOccTC84xldwKXJ0vdNruTiVTrU07x69BL9DvuvJ6e3CBTIy2HKgT1K1q1VChTModKPEus7A=="
|
||||
},
|
||||
"@hibas123/utils": {
|
||||
"version": "2.2.18",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hibas123/nodelogging",
|
||||
"version": "3.0.10",
|
||||
"version": "3.1.0",
|
||||
"description": "",
|
||||
"main": "out/index.js",
|
||||
"types": "out/index.d.ts",
|
||||
@ -32,7 +32,7 @@
|
||||
"typescript": "^4.2.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hibas123/logging": "^3.0.8",
|
||||
"@hibas123/logging": "^3.1.0",
|
||||
"@hibas123/utils": "^2.2.18"
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,20 @@
|
||||
import { Lock } from "@hibas123/utils";
|
||||
import * as fs from "fs";
|
||||
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;
|
||||
|
||||
export class LoggingFiles implements Adapter {
|
||||
level = LoggingTypes.Debug;
|
||||
|
||||
file: Files;
|
||||
constructor(private filename: string, private maxFileSize = MAX_FILE_SIZE) {}
|
||||
|
||||
setLevel(level: LoggingTypes) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
init() {
|
||||
if (!this.file) {
|
||||
this.file = Files.getFile(this.filename);
|
||||
@ -41,11 +47,7 @@ const Debounce = (callback: () => void, iv = 500, max = 100) => {
|
||||
trigger: () => {
|
||||
curr++;
|
||||
if (curr >= max) {
|
||||
if (to) {
|
||||
clearTimeout(to);
|
||||
to = undefined;
|
||||
}
|
||||
curr = 0;
|
||||
curr = 0; // not clearing timeout, since this is a very high cost operation
|
||||
callback();
|
||||
} else if (!to) {
|
||||
to = setTimeout(() => {
|
||||
@ -55,6 +57,7 @@ const Debounce = (callback: () => void, iv = 500, max = 100) => {
|
||||
}, iv);
|
||||
}
|
||||
},
|
||||
close: () => {},
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user