@spinajs/log 2.0.38 → 2.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bootstrap.js +13 -24
- package/lib/bootstrap.js.map +1 -1
- package/lib/log.d.ts +2 -2
- package/lib/log.js +7 -2
- package/lib/log.js.map +1 -1
- package/lib/schemas/log.configuration.js +1 -10
- package/lib/schemas/log.configuration.js.map +1 -1
- package/lib/targets/FileTarget.d.ts +18 -22
- package/lib/targets/FileTarget.js +168 -135
- package/lib/targets/FileTarget.js.map +1 -1
- package/package.json +7 -7
package/lib/bootstrap.js
CHANGED
|
@@ -10,36 +10,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.LogBotstrapper = void 0;
|
|
13
|
-
const FileTarget_1 = require("./targets/FileTarget");
|
|
14
13
|
const di_1 = require("@spinajs/di");
|
|
15
14
|
const log_1 = require("./log");
|
|
16
15
|
const log_configuration_1 = __importDefault(require("./schemas/log.configuration"));
|
|
17
16
|
let LogBotstrapper = class LogBotstrapper extends di_1.Bootstrapper {
|
|
18
17
|
bootstrap() {
|
|
19
18
|
di_1.DI.register(log_configuration_1.default).asValue("__configurationSchema__");
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}).as("FileTarget");
|
|
34
|
-
di_1.DI.register(FileTarget_1.FileTarget).as("__file_target_implementation__");
|
|
35
|
-
process.on("uncaughtException", (err) => {
|
|
36
|
-
const log = di_1.DI.resolve(log_1.Log, ["process"]);
|
|
37
|
-
log.fatal(err, "Unhandled exception occured");
|
|
38
|
-
});
|
|
39
|
-
process.on("unhandledRejection", (reason, p) => {
|
|
40
|
-
const log = di_1.DI.resolve(log_1.Log, ["process"]);
|
|
41
|
-
log.fatal(reason, "Unhandled rejection at Promise %s", p);
|
|
42
|
-
});
|
|
19
|
+
// check if we run tests,
|
|
20
|
+
// hook for uncaughtException causes to not showing
|
|
21
|
+
// mocha errors in console
|
|
22
|
+
if (!process.env.TESTING) {
|
|
23
|
+
process.on("uncaughtException", (err) => {
|
|
24
|
+
const log = di_1.DI.resolve(log_1.Log, ["process"]);
|
|
25
|
+
log.fatal(err, "Unhandled exception occured");
|
|
26
|
+
});
|
|
27
|
+
process.on("unhandledRejection", (reason, p) => {
|
|
28
|
+
const log = di_1.DI.resolve(log_1.Log, ["process"]);
|
|
29
|
+
log.fatal(reason, "Unhandled rejection at Promise %s", p);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
43
32
|
}
|
|
44
33
|
};
|
|
45
34
|
LogBotstrapper = __decorate([
|
package/lib/bootstrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAA2D;AAC3D,+BAA4B;AAC5B,oFAA+D;AAG/D,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,iBAAY;IACvC,SAAS;QACd,OAAE,CAAC,QAAQ,CAAC,2BAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAErE,yBAAyB;QACzB,mDAAmD;QACnD,0BAA0B;QAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE;YACxB,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;gBACtC,MAAM,GAAG,GAAG,OAAE,CAAC,OAAO,CAAC,SAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;gBACzC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,6BAA6B,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC7C,MAAM,GAAG,GAAG,OAAE,CAAC,OAAO,CAAC,SAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;gBACzC,GAAG,CAAC,KAAK,CAAC,MAAe,EAAE,mCAAmC,EAAE,CAAC,CAAC,CAAC;YACrE,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AAnBY,cAAc;IAD1B,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,cAAc,CAmB1B;AAnBY,wCAAc"}
|
package/lib/log.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Container,
|
|
1
|
+
import { Container, SyncService } from "@spinajs/di";
|
|
2
2
|
import { ILogOptions, ILogRule, ILogEntry, LogVariables, ILog, ILogTargetDesc } from "@spinajs/log-common";
|
|
3
3
|
/**
|
|
4
4
|
* Default log implementation interface. Taken from bunyan. Feel free to implement own.
|
|
5
5
|
*/
|
|
6
|
-
export declare class Log extends
|
|
6
|
+
export declare class Log extends SyncService implements ILog {
|
|
7
7
|
Name: string;
|
|
8
8
|
protected Parent?: Log;
|
|
9
9
|
/**
|
package/lib/log.js
CHANGED
|
@@ -40,7 +40,7 @@ function wrapWrite(level) {
|
|
|
40
40
|
/**
|
|
41
41
|
* Default log implementation interface. Taken from bunyan. Feel free to implement own.
|
|
42
42
|
*/
|
|
43
|
-
let Log = Log_1 = class Log extends di_1.
|
|
43
|
+
let Log = Log_1 = class Log extends di_1.SyncService {
|
|
44
44
|
constructor(Name, variables, Parent) {
|
|
45
45
|
super();
|
|
46
46
|
this.Name = Name;
|
|
@@ -115,7 +115,12 @@ let Log = Log_1 = class Log extends di_1.SyncModule {
|
|
|
115
115
|
}
|
|
116
116
|
write(entry) {
|
|
117
117
|
if (entry.Variables.logger === this.Name) {
|
|
118
|
-
return Promise.allSettled(this.Targets.filter((t) => entry.Level >= log_common_1.StrToLogLevel[t.rule.level]).map((t) =>
|
|
118
|
+
return Promise.allSettled(this.Targets.filter((t) => entry.Level >= log_common_1.StrToLogLevel[t.rule.level]).map((t) => {
|
|
119
|
+
if (!t.instance) {
|
|
120
|
+
throw new exceptions_1.InvalidOperation(`Target for rule ${t.rule.name} not exists`);
|
|
121
|
+
}
|
|
122
|
+
return t.instance.write(entry);
|
|
123
|
+
}));
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
child(name, variables) {
|
package/lib/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;AAC1D,0DAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;AAC1D,0DAAuD;AACvD,oCAA8F;AAC9F,oDAA6L;AAC7L,oEAA0C;AAC1C,oDAAsE;AAEtE,SAAS,SAAS,CAAY,KAAe;IAC3C,OAAO,CAAC,GAAmB,EAAE,OAAuB,EAAE,GAAG,IAAW,EAAE,EAAE;QACtE,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,mCAAsB,EAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;SACpG;aAAM;YACL,IAAI,OAAO,EAAE;gBACX,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,mCAAsB,EAAC,GAAG,EAAE,IAAI,EAA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OAAe,EAAE,EAAE;IACpE,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QAC5B,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KACjC;IAED,OAAO,SAAS,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,6CAA6C;AAC7C,2CAA2C;AAC3C,2DAA2D;AAC3D,2CAA2C;AAC3C,OAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AAE9C,6CAA6C;AAC7C,mDAAmD;AACnD,cAAc;AACd,OAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;AAExC,uCAAuC;AACvC,8BAA8B;AAC9B,2CAA2C;AAC3C,OAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC"}
|
|
@@ -67,16 +67,7 @@ const CONFIGURATION_SCHEMA = {
|
|
|
67
67
|
},
|
|
68
68
|
level: {
|
|
69
69
|
type: "string",
|
|
70
|
-
enum: [
|
|
71
|
-
"trace",
|
|
72
|
-
"debug",
|
|
73
|
-
"warn",
|
|
74
|
-
"info",
|
|
75
|
-
"error",
|
|
76
|
-
"fatal",
|
|
77
|
-
"security",
|
|
78
|
-
"success",
|
|
79
|
-
],
|
|
70
|
+
enum: ["trace", "debug", "warn", "info", "error", "fatal", "security", "success"],
|
|
80
71
|
},
|
|
81
72
|
target: {
|
|
82
73
|
oneOf: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.configuration.js","sourceRoot":"","sources":["../../src/schemas/log.configuration.ts"],"names":[],"mappings":";;AAAA,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,uCAAuC;IAC5C,oBAAoB,EAAE,QAAQ;IAC9B,WAAW,EAAE,wCAAwC;IACrD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,OAAO,EAAE;YACP,WAAW,
|
|
1
|
+
{"version":3,"file":"log.configuration.js","sourceRoot":"","sources":["../../src/schemas/log.configuration.ts"],"names":[],"mappings":";;AAAA,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,uCAAuC;IAC5C,oBAAoB,EAAE,QAAQ;IAC9B,WAAW,EAAE,wCAAwC;IACrD,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,OAAO,EAAE;YACP,WAAW,EAAE,wEAAwE;YACrF,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC;YACX,WAAW,EAAE,IAAI;YACjB,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,MAAM,EAAE;wBACN,IAAI,EAAE,QAAQ;qBACf;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,QAAQ;qBACf;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,QAAQ;qBACf;oBACD,OAAO,EAAE;wBACP,IAAI,EAAE,SAAS;qBAChB;oBACD,IAAI,EAAE;wBACJ,IAAI,EAAE,QAAQ;qBACf;oBACD,WAAW,EAAE;wBACX,IAAI,EAAE,QAAQ;qBACf;oBACD,OAAO,EAAE;wBACP,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,KAAK;qBACf;oBACD,QAAQ,EAAE;wBACR,IAAI,EAAE,SAAS;qBAChB;oBACD,MAAM,EAAE;wBACN,IAAI,EAAE,QAAQ;qBACf;oBACD,eAAe,EAAE;wBACf,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,CAAC;qBACX;oBACD,UAAU,EAAE;wBACV,IAAI,EAAE,SAAS;wBACf,OAAO,EAAE,IAAI;qBACd;iBACF;gBACD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;aAC3B;SACF;QACD,KAAK,EAAE;YACL,WAAW,EAAE,2CAA2C;YACxD,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC;YACX,WAAW,EAAE,IAAI;YACjB,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE;wBACJ,IAAI,EAAE,QAAQ;qBACf;oBACD,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC;qBAClF;oBACD,MAAM,EAAE;wBACN,KAAK,EAAE;4BACL;gCACE,IAAI,EAAE,QAAQ;6BACf;4BACD;gCACE,IAAI,EAAE,OAAO;gCACb,KAAK,EAAE;oCACL,IAAI,EAAE,QAAQ;iCACf;6BACF;yBACF;qBACF;iBACF;gBACD,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;aACtC;SACF;KACF;CACF,CAAC;AAEF,kBAAe,oBAAoB,CAAC"}
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
|
|
4
|
-
import { IFileTargetOptions, ILogEntry, LogTarget } from "@spinajs/log-common";
|
|
3
|
+
import { IInstanceCheck } from "@spinajs/di";
|
|
4
|
+
import { IFileTargetOptions, ILog, ILogEntry, LogTarget } from "@spinajs/log-common";
|
|
5
5
|
import * as fs from "fs";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
_read(): void;
|
|
6
|
+
import "@spinajs/configuration-common";
|
|
7
|
+
declare enum FileTargetStatus {
|
|
8
|
+
WRITTING = 0,
|
|
9
|
+
PENDING = 1,
|
|
10
|
+
IDLE = 2
|
|
12
11
|
}
|
|
13
|
-
export declare class FileTarget extends LogTarget<IFileTargetOptions> {
|
|
12
|
+
export declare class FileTarget extends LogTarget<IFileTargetOptions> implements IInstanceCheck {
|
|
13
|
+
protected Log: ILog;
|
|
14
14
|
LogDirPath: string;
|
|
15
|
-
LogFileName: string;
|
|
16
|
-
LogPath: string;
|
|
17
|
-
LogFileExt: string;
|
|
18
|
-
LogBaseName: string;
|
|
19
15
|
ArchiveDirPath: string;
|
|
20
|
-
protected RotateJob: Job;
|
|
21
|
-
protected CurrentFileSize: number;
|
|
22
|
-
protected IsArchiving: boolean;
|
|
23
16
|
protected WriteStream: fs.WriteStream;
|
|
24
|
-
protected
|
|
25
|
-
|
|
17
|
+
protected Buffer: string[];
|
|
18
|
+
protected ArchiveTimer: NodeJS.Timer;
|
|
19
|
+
protected FlushTimer: NodeJS.Timer;
|
|
20
|
+
protected Status: FileTargetStatus;
|
|
21
|
+
protected ArchiveStatus: FileTargetStatus;
|
|
22
|
+
__checkInstance__(creationOptions: IFileTargetOptions): boolean;
|
|
23
|
+
resolve(): void;
|
|
24
|
+
protected flush(): void;
|
|
25
|
+
dispose(): Promise<void>;
|
|
26
26
|
write(data: ILogEntry): Promise<void>;
|
|
27
27
|
protected archive(): void;
|
|
28
|
-
private rotate;
|
|
29
|
-
private initialize;
|
|
30
|
-
private close;
|
|
31
|
-
private open;
|
|
32
28
|
}
|
|
33
29
|
export {};
|
|
@@ -28,189 +28,222 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
28
28
|
__setModuleDefault(result, mod);
|
|
29
29
|
return result;
|
|
30
30
|
};
|
|
31
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
+
};
|
|
31
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
35
|
exports.FileTarget = void 0;
|
|
36
|
+
/* eslint-disable security/detect-object-injection */
|
|
33
37
|
const os_1 = require("os");
|
|
34
38
|
/* eslint security/detect-non-literal-fs-filename:0 -- Safe as no value holds user input */
|
|
35
39
|
const di_1 = require("@spinajs/di");
|
|
36
40
|
const log_common_1 = require("@spinajs/log-common");
|
|
37
41
|
const fs = __importStar(require("fs"));
|
|
38
42
|
const path = __importStar(require("path"));
|
|
39
|
-
const node_schedule_1 = require("node-schedule");
|
|
40
43
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
41
44
|
const glob = __importStar(require("glob"));
|
|
42
45
|
const zlib = __importStar(require("zlib"));
|
|
43
46
|
const configuration_1 = require("@spinajs/configuration");
|
|
44
47
|
const stream_1 = require("stream");
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
_read() {
|
|
59
|
-
let ok = true;
|
|
60
|
-
let val = null;
|
|
61
|
-
do {
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
63
|
-
val = this.LogQueue.shift();
|
|
64
|
-
if (val) {
|
|
65
|
-
ok = super.push(val);
|
|
66
|
-
if (!ok) {
|
|
67
|
-
this.LogQueue.unshift(val);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
} while (ok && val);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
48
|
+
const decorators_1 = require("./../decorators");
|
|
49
|
+
require("@spinajs/configuration-common");
|
|
50
|
+
var FileTargetStatus;
|
|
51
|
+
(function (FileTargetStatus) {
|
|
52
|
+
FileTargetStatus[FileTargetStatus["WRITTING"] = 0] = "WRITTING";
|
|
53
|
+
FileTargetStatus[FileTargetStatus["PENDING"] = 1] = "PENDING";
|
|
54
|
+
FileTargetStatus[FileTargetStatus["IDLE"] = 2] = "IDLE";
|
|
55
|
+
})(FileTargetStatus || (FileTargetStatus = {}));
|
|
56
|
+
// we mark per instance check becouse we can have multiple file targes
|
|
57
|
+
// for different files/paths/logs but we dont want to create every time writer for same.
|
|
73
58
|
let FileTarget = class FileTarget extends log_common_1.LogTarget {
|
|
74
59
|
constructor() {
|
|
75
60
|
super(...arguments);
|
|
76
|
-
this.
|
|
61
|
+
this.Buffer = [];
|
|
62
|
+
this.Status = FileTargetStatus.IDLE;
|
|
63
|
+
this.ArchiveStatus = FileTargetStatus.IDLE;
|
|
77
64
|
}
|
|
78
|
-
|
|
65
|
+
__checkInstance__(creationOptions) {
|
|
66
|
+
return this.Options.name === creationOptions.name;
|
|
67
|
+
}
|
|
68
|
+
resolve() {
|
|
79
69
|
this.Options.options = Object.assign({
|
|
80
70
|
compress: true,
|
|
81
71
|
maxSize: 1024 * 1024,
|
|
82
72
|
maxArchiveFiles: 5,
|
|
73
|
+
archiveInterval: 3 * 60,
|
|
83
74
|
}, this.Options.options);
|
|
84
|
-
this.
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
75
|
+
this.LogDirPath = path.dirname(path.resolve((0, configuration_1.format)(null, this.Options.options.path)));
|
|
76
|
+
this.ArchiveDirPath = this.Options.options.archivePath ? path.resolve((0, configuration_1.format)(null, this.Options.options.archivePath)) : this.LogDirPath;
|
|
77
|
+
if (!this.LogDirPath) {
|
|
78
|
+
throw new exceptions_1.InvalidOption("Missing LogDirPath log option");
|
|
79
|
+
}
|
|
80
|
+
if (!fs.existsSync(this.LogDirPath)) {
|
|
81
|
+
fs.mkdirSync(this.LogDirPath);
|
|
82
|
+
}
|
|
83
|
+
if (this.ArchiveDirPath) {
|
|
84
|
+
if (!fs.existsSync(this.ArchiveDirPath)) {
|
|
85
|
+
fs.mkdirSync(this.ArchiveDirPath);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// flush all buffered messages at least once per second
|
|
89
|
+
// we do this, becouse buffer can not be filled
|
|
90
|
+
// and we could wait unknown amount of time before messages are written to file
|
|
91
|
+
this.FlushTimer = setInterval(() => {
|
|
92
|
+
// do not flush, if we already writting to file
|
|
93
|
+
if (this.Status !== FileTargetStatus.IDLE && this.ArchiveStatus !== FileTargetStatus.IDLE) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
setImmediate(() => {
|
|
97
|
+
this.flush();
|
|
98
|
+
});
|
|
99
|
+
}, 1000);
|
|
100
|
+
// every 3 minutes try to archive log files
|
|
101
|
+
this.ArchiveTimer = setInterval(() => {
|
|
102
|
+
// do not archive if we already doing it
|
|
103
|
+
if (this.Status !== FileTargetStatus.IDLE && this.ArchiveStatus !== FileTargetStatus.IDLE) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.ArchiveStatus = FileTargetStatus.PENDING;
|
|
107
|
+
// at end of nodejs event loop
|
|
108
|
+
setImmediate(() => {
|
|
109
|
+
this.archive();
|
|
110
|
+
});
|
|
111
|
+
}, this.Options.options.archiveInterval * 1000);
|
|
87
112
|
super.resolve();
|
|
88
113
|
}
|
|
114
|
+
flush() {
|
|
115
|
+
if (this.Buffer.length === 0) {
|
|
116
|
+
this.Status = FileTargetStatus.IDLE;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.Status = FileTargetStatus.WRITTING;
|
|
120
|
+
// we calculate log path every time to allow for
|
|
121
|
+
// dynamic path creation eg. based on timestamp
|
|
122
|
+
const logFileName = (0, configuration_1.format)({ logger: this.Options.name }, path.basename(this.Options.options.path));
|
|
123
|
+
const logPath = path.join(this.LogDirPath, logFileName);
|
|
124
|
+
fs.appendFile(logPath, this.Buffer.join(os_1.EOL) + os_1.EOL, (err) => {
|
|
125
|
+
// log error message to others if applicable eg. console
|
|
126
|
+
if (err) {
|
|
127
|
+
this.Log.error(err, `Cannot write log messages to file target at path ${logPath}`);
|
|
128
|
+
}
|
|
129
|
+
this.Log.trace(`Wrote buffered messages to log file at path ${logPath}, buffer size: ${this.Options.options.maxBufferSize}`);
|
|
130
|
+
this.Buffer = [];
|
|
131
|
+
this.Status = FileTargetStatus.IDLE;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
async dispose() {
|
|
135
|
+
// stop archiving
|
|
136
|
+
clearInterval(this.ArchiveTimer);
|
|
137
|
+
// stop flush timer
|
|
138
|
+
clearInterval(this.FlushTimer);
|
|
139
|
+
// write all messages from buffer
|
|
140
|
+
this.flush();
|
|
141
|
+
}
|
|
89
142
|
async write(data) {
|
|
90
143
|
if (!this.Options.enabled) {
|
|
91
144
|
return;
|
|
92
145
|
}
|
|
93
|
-
const lEntry = (0, configuration_1.format)(data.Variables, this.Options.layout)
|
|
94
|
-
this.
|
|
95
|
-
if
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
146
|
+
const lEntry = (0, configuration_1.format)(data.Variables, this.Options.layout);
|
|
147
|
+
this.Buffer.push(lEntry);
|
|
148
|
+
// if we already writting, skip buffer check & write to file
|
|
149
|
+
// wait until write is finished
|
|
150
|
+
if (this.Status !== FileTargetStatus.IDLE || this.ArchiveStatus !== FileTargetStatus.IDLE) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (this.Buffer.length >= this.Options.options.maxBufferSize) {
|
|
154
|
+
this.Status = FileTargetStatus.PENDING;
|
|
155
|
+
// write at end of nodejs event loop all buffered messages at once
|
|
156
|
+
setImmediate(() => {
|
|
157
|
+
this.flush();
|
|
158
|
+
});
|
|
99
159
|
}
|
|
100
160
|
}
|
|
101
161
|
archive() {
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
.sync(path.join(this.ArchiveDirPath, `archived_
|
|
162
|
+
const { ext } = path.parse(path.basename(this.Options.options.path));
|
|
163
|
+
const aFiles = glob
|
|
164
|
+
.sync(path.join(this.ArchiveDirPath, `archived_*{${ext},.gzip}`))
|
|
105
165
|
.map((f) => {
|
|
106
166
|
return {
|
|
107
167
|
name: f,
|
|
108
168
|
stat: fs.statSync(f),
|
|
109
169
|
};
|
|
110
170
|
})
|
|
111
|
-
.sort((
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
171
|
+
.sort((a, b) => a.stat.mtime.getTime() - b.stat.mtime.getTime());
|
|
172
|
+
const lFiles = glob
|
|
173
|
+
.sync(path.join(this.LogDirPath, `*${ext}`))
|
|
174
|
+
.map((f) => {
|
|
175
|
+
return {
|
|
176
|
+
name: f,
|
|
177
|
+
stat: fs.statSync(f),
|
|
178
|
+
};
|
|
179
|
+
})
|
|
180
|
+
.sort((a, b) => a.stat.mtime.getTime() - b.stat.mtime.getTime());
|
|
181
|
+
// clear archived files above limit
|
|
182
|
+
if (aFiles.length > this.Options.options.maxArchiveFiles) {
|
|
183
|
+
for (let i = 0; i < aFiles.length - this.Options.options.maxArchiveFiles; i++) {
|
|
184
|
+
fs.unlink(aFiles[i].name, (err) => {
|
|
185
|
+
if (err) {
|
|
186
|
+
this.Log.error(err, `Cannot delete archived file at path ${aFiles[i - 1].name}`);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
this.Log.info(`Deleted archived file at path ${aFiles[i].name}`);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
117
193
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
194
|
+
// now move log files that are above limited file size or old
|
|
195
|
+
const filesToArchive = lFiles.filter((x) => {
|
|
196
|
+
return x.stat.size > this.Options.options.maxSize || lFiles.indexOf(x) <= lFiles.length - 2;
|
|
197
|
+
});
|
|
198
|
+
if (filesToArchive.length === 0) {
|
|
199
|
+
this.ArchiveStatus = FileTargetStatus.IDLE;
|
|
200
|
+
}
|
|
201
|
+
for (let i = 0; i < filesToArchive.length; i++) {
|
|
202
|
+
const { name, ext } = path.parse(path.basename(lFiles[i].name));
|
|
203
|
+
// get number of files with same name, eg. during a day, multiple log files can be produced
|
|
204
|
+
const lArchiFiles = glob.sync(path.join(this.ArchiveDirPath, `archived_${name}*{${ext},.gzip}`));
|
|
205
|
+
const archPath = path.join(this.ArchiveDirPath, `archived_${name}_${lArchiFiles.length + 1}${ext}`);
|
|
206
|
+
fs.rename(lFiles[i].name, archPath, (err) => {
|
|
207
|
+
if (err) {
|
|
208
|
+
this.Log.error(err, `Cannot move log file ${name} to archive at path ${archPath}`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (this.Options.options.compress) {
|
|
212
|
+
this.Log.trace(`Compressing archive log at path ${archPath}`);
|
|
213
|
+
const zippedPath = path.join(this.ArchiveDirPath, `archived_${name}_${lArchiFiles.length + 1}${ext}.gzip`);
|
|
214
|
+
const zip = zlib.createGzip();
|
|
215
|
+
const read = fs.createReadStream(archPath);
|
|
216
|
+
const write = fs.createWriteStream(zippedPath);
|
|
217
|
+
(0, stream_1.pipeline)(read, zip, write, (err) => {
|
|
218
|
+
if (err) {
|
|
219
|
+
this.Log.error(err, `Cannot compress archived file at path ${archPath}`);
|
|
220
|
+
fs.unlink(zippedPath, () => {
|
|
135
221
|
return;
|
|
136
222
|
});
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (files.length >= this.Options.options.maxArchiveFiles) {
|
|
140
|
-
fs.unlink(files[0].name, () => {
|
|
141
223
|
return;
|
|
224
|
+
}
|
|
225
|
+
this.Log.info(`Succesyfully compressed archive log at path ${zippedPath}`);
|
|
226
|
+
fs.unlink(archPath, (err) => {
|
|
227
|
+
if (err) {
|
|
228
|
+
this.Log.error(err, `Cannot delete archived log after compression at path ${archPath}`);
|
|
229
|
+
}
|
|
142
230
|
});
|
|
143
|
-
|
|
231
|
+
this.ArchiveStatus = FileTargetStatus.IDLE;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
this.ArchiveStatus = FileTargetStatus.IDLE;
|
|
144
236
|
}
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
this.close();
|
|
148
|
-
}
|
|
149
|
-
rotate() {
|
|
150
|
-
if (this.Options.options.rotate) {
|
|
151
|
-
this.RotateJob = (0, node_schedule_1.scheduleJob)(`LogScheduleJob`, this.Options.options.rotate, () => {
|
|
152
|
-
this.archive();
|
|
153
237
|
});
|
|
154
238
|
}
|
|
155
239
|
}
|
|
156
|
-
initialize() {
|
|
157
|
-
this.CurrentFileSize = 0;
|
|
158
|
-
this.IsArchiving = false;
|
|
159
|
-
this.LogDirPath = path.dirname(path.resolve((0, configuration_1.format)(null, this.Options.options.path)));
|
|
160
|
-
this.ArchiveDirPath = this.Options.options.archivePath ? path.resolve((0, configuration_1.format)(null, this.Options.options.archivePath)) : this.LogDirPath;
|
|
161
|
-
this.LogFileName = (0, configuration_1.format)({ logger: this.Options.name }, path.basename(this.Options.options.path));
|
|
162
|
-
this.LogPath = path.join(this.LogDirPath, this.LogFileName);
|
|
163
|
-
const { name, ext } = path.parse(this.LogFileName);
|
|
164
|
-
this.LogFileExt = ext;
|
|
165
|
-
this.LogBaseName = name;
|
|
166
|
-
if (!this.LogDirPath) {
|
|
167
|
-
throw new exceptions_1.InvalidOption("Missing LogDirPath log option");
|
|
168
|
-
}
|
|
169
|
-
if (!fs.existsSync(this.LogDirPath)) {
|
|
170
|
-
fs.mkdirSync(this.LogDirPath);
|
|
171
|
-
}
|
|
172
|
-
if (this.ArchiveDirPath) {
|
|
173
|
-
if (!fs.existsSync(this.ArchiveDirPath)) {
|
|
174
|
-
fs.mkdirSync(this.ArchiveDirPath);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
const { size } = fs.statSync(this.LogPath);
|
|
179
|
-
this.CurrentFileSize = size;
|
|
180
|
-
}
|
|
181
|
-
catch (_a) { }
|
|
182
|
-
this.open();
|
|
183
|
-
}
|
|
184
|
-
close() {
|
|
185
|
-
this.LogStream.unpipe(this.WriteStream);
|
|
186
|
-
this.WriteStream.end();
|
|
187
|
-
this.WriteStream = null;
|
|
188
|
-
}
|
|
189
|
-
open() {
|
|
190
|
-
this.WriteStream = fs.createWriteStream(this.LogPath, {
|
|
191
|
-
flags: "a",
|
|
192
|
-
encoding: "utf-8",
|
|
193
|
-
});
|
|
194
|
-
this.WriteStream.once("open", () => {
|
|
195
|
-
void this.write((0, log_common_1.createLogMessageObject)(`Log file opened at ${this.LogPath}`, [], log_common_1.LogLevel.Trace, "log-file-target", {}));
|
|
196
|
-
if (this.WriteStream) {
|
|
197
|
-
this.LogStream.pipe(this.WriteStream);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
this.WriteStream.once("close", () => {
|
|
201
|
-
void this.write((0, log_common_1.createLogMessageObject)(`Log file closed at ${this.LogPath}`, [], log_common_1.LogLevel.Trace, "log-file-target", {}));
|
|
202
|
-
});
|
|
203
|
-
this.WriteStream.once("error", (err) => {
|
|
204
|
-
this.LogStream.unpipe(this.WriteStream);
|
|
205
|
-
void this.write((0, log_common_1.createLogMessageObject)(err, `Cannot write to log file at ${this.LogPath}`, log_common_1.LogLevel.Error, "log-file-target", {}));
|
|
206
|
-
setTimeout(() => {
|
|
207
|
-
this.initialize();
|
|
208
|
-
}, 1000);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
240
|
};
|
|
241
|
+
__decorate([
|
|
242
|
+
(0, decorators_1.Logger)("LogFileTarget"),
|
|
243
|
+
__metadata("design:type", Object)
|
|
244
|
+
], FileTarget.prototype, "Log", void 0);
|
|
212
245
|
FileTarget = __decorate([
|
|
213
|
-
(0, di_1.
|
|
246
|
+
(0, di_1.PerInstanceCheck)(),
|
|
214
247
|
(0, di_1.Injectable)("FileTarget")
|
|
215
248
|
], FileTarget);
|
|
216
249
|
exports.FileTarget = FileTarget;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileTarget.js","sourceRoot":"","sources":["../../src/targets/FileTarget.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileTarget.js","sourceRoot":"","sources":["../../src/targets/FileTarget.ts"],"names":[],"mappings":";;;;;;;;;;;;;;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AAC,GAAG,EAAE,wDAAwD,QAAQ,EAAE,CAAC,CAAC;6BACzF;wBACH,CAAC,CAAC,CAAC;wBAEH,IAAI,CAAC,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC;oBAC7C,CAAC,CAAC,CAAC;iBACJ;qBAAM;oBACL,IAAI,CAAC,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC;iBAC5C;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AAxOC;IADC,IAAA,mBAAM,EAAC,eAAe,CAAC;;uCACJ;AAFT,UAAU;IAFtB,IAAA,qBAAgB,GAAE;IAClB,IAAA,eAAU,EAAC,YAAY,CAAC;GACZ,UAAU,CA0OtB;AA1OY,gCAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spinajs/log",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.44",
|
|
4
4
|
"description": "Log lib for all spinejs related libs",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"homepage": "https://github.com/spinajs/log#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@colors/colors": "^1.5.0",
|
|
30
|
-
"@spinajs/configuration": "^2.0.
|
|
31
|
-
"@spinajs/di": "^2.0.
|
|
32
|
-
"@spinajs/exceptions": "^2.0.
|
|
33
|
-
"@spinajs/log-common": "^2.0.
|
|
30
|
+
"@spinajs/configuration": "^2.0.44",
|
|
31
|
+
"@spinajs/di": "^2.0.44",
|
|
32
|
+
"@spinajs/exceptions": "^2.0.39",
|
|
33
|
+
"@spinajs/log-common": "^2.0.44",
|
|
34
34
|
"ajv": "^8.11.0",
|
|
35
35
|
"chalk": "4.1.2",
|
|
36
36
|
"glob": "^7.2.0",
|
|
37
37
|
"glob-to-regexp": "^0.4.1",
|
|
38
38
|
"lodash": "^4.17.14",
|
|
39
|
-
"luxon": "^2.
|
|
39
|
+
"luxon": "^3.2.1",
|
|
40
40
|
"node-schedule": "^2.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"@types/node-schedule": "^1.3.2",
|
|
47
47
|
"mock-fs": "^5.1.2"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "1857a6e3626e0fed22ffb0b44b48d587c79898db"
|
|
50
50
|
}
|