@spinajs/log 1.1.9 → 1.2.7
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/.eslintignore +2 -0
- package/.eslintrc.js +43 -0
- package/lib/config/log.js +3 -3
- package/lib/config/log.js.map +1 -1
- package/lib/decorators.d.ts +3 -3
- package/lib/decorators.js +4 -4
- package/lib/decorators.js.map +1 -1
- package/lib/index.d.ts +6 -2
- package/lib/index.js +7 -2
- package/lib/index.js.map +1 -1
- package/lib/log.d.ts +8 -32
- package/lib/log.js +59 -123
- package/lib/log.js.map +1 -1
- package/lib/logger.d.ts +3 -7
- package/lib/logger.js +14 -24
- package/lib/logger.js.map +1 -1
- package/lib/schemas/log.configuration.d.ts +1 -0
- package/lib/schemas/log.configuration.js +91 -97
- package/lib/schemas/log.configuration.js.map +1 -1
- package/lib/targets/BlackHoleTarget.d.ts +3 -3
- package/lib/targets/BlackHoleTarget.js.map +1 -1
- package/lib/targets/ColoredConsoleTarget.d.ts +4 -5
- package/lib/targets/ColoredConsoleTarget.js +18 -14
- package/lib/targets/ColoredConsoleTarget.js.map +1 -1
- package/lib/targets/FileTarget.d.ts +3 -4
- package/lib/targets/FileTarget.js +84 -112
- package/lib/targets/FileTarget.js.map +1 -1
- package/lib/targets/LogTarget.d.ts +10 -5
- package/lib/targets/LogTarget.js +38 -36
- package/lib/targets/LogTarget.js.map +1 -1
- package/lib/targets/index.d.ts +1 -0
- package/lib/targets/index.js +1 -0
- package/lib/targets/index.js.map +1 -1
- package/lib/types.d.ts +13 -10
- package/lib/types.js +8 -8
- package/lib/types.js.map +1 -1
- package/lib/variables/date.d.ts +1 -1
- package/lib/variables/date.js +7 -7
- package/lib/variables/date.js.map +1 -1
- package/lib/variables/env.d.ts +1 -1
- package/lib/variables/env.js +4 -4
- package/lib/variables/env.js.map +1 -1
- package/lib/variables/process.d.ts +2 -3
- package/lib/variables/process.js +4 -16
- package/lib/variables/process.js.map +1 -1
- package/package.json +14 -39
- package/tsconfig.build.json +9 -0
|
@@ -1,104 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const CONFIGURATION_SCHEMA = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
$id: "spinajs/log.configuration.schema.json",
|
|
5
|
+
$configurationModule: "logger",
|
|
6
|
+
description: "Logger configuration option validation",
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
targets: {
|
|
10
|
+
description: "Log target, where log messages should be written to, and their options",
|
|
11
|
+
type: "array",
|
|
12
|
+
minItems: 1,
|
|
13
|
+
uniqueItems: true,
|
|
14
|
+
items: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
layout: {
|
|
18
|
+
type: "string",
|
|
18
19
|
},
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
name: {
|
|
21
|
+
type: "string",
|
|
21
22
|
},
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
type: {
|
|
24
|
+
type: "string",
|
|
24
25
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
theme: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
security: {
|
|
30
|
+
type: "string",
|
|
30
31
|
},
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
fatal: {
|
|
33
|
+
type: "string",
|
|
33
34
|
},
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
error: {
|
|
36
|
+
type: "string",
|
|
36
37
|
},
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
warn: {
|
|
39
|
+
type: "string",
|
|
39
40
|
},
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
success: {
|
|
42
|
+
type: "string",
|
|
42
43
|
},
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
info: {
|
|
45
|
+
type: "string",
|
|
45
46
|
},
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
debug: {
|
|
48
|
+
type: "string",
|
|
48
49
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
50
|
+
trace: {
|
|
51
|
+
type: "string",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
enabled: {
|
|
56
|
+
type: "boolean",
|
|
53
57
|
},
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
path: {
|
|
59
|
+
type: "string",
|
|
56
60
|
},
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
archivePath: {
|
|
62
|
+
type: "string",
|
|
59
63
|
},
|
|
60
|
-
|
|
61
|
-
|
|
64
|
+
maxSize: {
|
|
65
|
+
type: "integer",
|
|
66
|
+
minimum: 10000,
|
|
62
67
|
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"minimum": 10000
|
|
68
|
+
compress: {
|
|
69
|
+
type: "boolean",
|
|
66
70
|
},
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
rotate: {
|
|
72
|
+
type: "string",
|
|
69
73
|
},
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
maxArchiveFiles: {
|
|
75
|
+
type: "integer",
|
|
76
|
+
minimum: 1,
|
|
72
77
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
bufferSize: {
|
|
79
|
+
type: "integer",
|
|
80
|
+
minimum: 1000,
|
|
76
81
|
},
|
|
77
|
-
"bufferSize": {
|
|
78
|
-
"type": "integer",
|
|
79
|
-
"minimum": 1000
|
|
80
|
-
}
|
|
81
82
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"type"
|
|
85
|
-
]
|
|
86
|
-
}
|
|
83
|
+
required: ["name", "type"],
|
|
84
|
+
},
|
|
87
85
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
rules: {
|
|
87
|
+
description: "Log rules, what log should be write where",
|
|
88
|
+
type: "array",
|
|
89
|
+
minItems: 1,
|
|
90
|
+
uniqueItems: true,
|
|
91
|
+
items: {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
name: {
|
|
95
|
+
type: "string",
|
|
98
96
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
level: {
|
|
98
|
+
type: "string",
|
|
99
|
+
enum: [
|
|
102
100
|
"trace",
|
|
103
101
|
"debug",
|
|
104
102
|
"warn",
|
|
@@ -106,31 +104,27 @@ const CONFIGURATION_SCHEMA = {
|
|
|
106
104
|
"error",
|
|
107
105
|
"fatal",
|
|
108
106
|
"security",
|
|
109
|
-
"success"
|
|
110
|
-
]
|
|
107
|
+
"success",
|
|
108
|
+
],
|
|
111
109
|
},
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
target: {
|
|
111
|
+
oneOf: [
|
|
114
112
|
{
|
|
115
|
-
|
|
113
|
+
type: "string",
|
|
116
114
|
},
|
|
117
115
|
{
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
]
|
|
124
|
-
}
|
|
116
|
+
type: "array",
|
|
117
|
+
items: {
|
|
118
|
+
type: "string",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
125
123
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
124
|
+
required: ["name", "level", "target"],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
134
128
|
};
|
|
135
129
|
exports.default = CONFIGURATION_SCHEMA;
|
|
136
130
|
//# sourceMappingURL=log.configuration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.configuration.js","sourceRoot":"","sources":["../../src/schemas/log.configuration.ts"],"names":[],"mappings":";;AAAA,MAAM,oBAAoB,GAAG;
|
|
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,EACT,wEAAwE;YAC1E,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,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,QAAQ,EAAE;gCACR,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;6BACf;4BACD,IAAI,EAAE;gCACJ,IAAI,EAAE,QAAQ;6BACf;4BACD,OAAO,EAAE;gCACP,IAAI,EAAE,QAAQ;6BACf;4BACD,IAAI,EAAE;gCACJ,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;6BACf;4BACD,KAAK,EAAE;gCAC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C;AAEF,kBAAe,oBAAoB,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LogTarget } from
|
|
1
|
+
import { ICommonTargetOptions } from "@spinajs/log-common";
|
|
2
|
+
import { LogTarget } from "./LogTarget";
|
|
3
3
|
/**
|
|
4
4
|
* Empty writer, usefull for tests or when we dont want to get any messages
|
|
5
5
|
*/
|
|
6
|
-
export declare class BlackHoleTarget extends LogTarget<
|
|
6
|
+
export declare class BlackHoleTarget extends LogTarget<ICommonTargetOptions> {
|
|
7
7
|
write(): Promise<void>;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlackHoleTarget.js","sourceRoot":"","sources":["../../src/targets/BlackHoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AACA,oCAAoD;AACpD,2CAAwC;AAExC;;GAEG;AAGH,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,
|
|
1
|
+
{"version":3,"file":"BlackHoleTarget.js","sourceRoot":"","sources":["../../src/targets/BlackHoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AACA,oCAAoD;AACpD,2CAAwC;AAExC;;GAEG;AAGH,IAAa,eAAe,GAA5B,MAAa,eAAgB,SAAQ,qBAA+B;IAC3D,KAAK,CAAC,KAAK;QAChB,OAAO;IACT,CAAC;CACF,CAAA;AAJY,eAAe;IAF3B,IAAA,cAAS,GAAE;IACX,IAAA,eAAU,EAAC,iBAAiB,CAAC;GACjB,eAAe,CAI3B;AAJY,0CAAe"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { IColoredConsoleTargetOptions,
|
|
2
|
-
import {
|
|
3
|
-
import { LogTarget } from './LogTarget';
|
|
1
|
+
import { IColoredConsoleTargetOptions, ILogEntry } from "@spinajs/log-common";
|
|
2
|
+
import { LogTarget } from "./LogTarget";
|
|
4
3
|
export declare const DEFAULT_THEME: {
|
|
5
4
|
security: string[];
|
|
6
5
|
fatal: string;
|
|
@@ -46,6 +45,6 @@ export declare class ColoredConsoleTarget extends LogTarget<IColoredConsoleTarge
|
|
|
46
45
|
(message?: any, ...optionalParams: any[]): void;
|
|
47
46
|
};
|
|
48
47
|
};
|
|
49
|
-
resolve(
|
|
50
|
-
write(data:
|
|
48
|
+
resolve(): void;
|
|
49
|
+
write(data: ILogEntry): Promise<void>;
|
|
51
50
|
}
|
|
@@ -7,21 +7,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ColoredConsoleTarget = exports.DEFAULT_THEME = void 0;
|
|
10
|
-
const
|
|
10
|
+
const log_common_1 = require("@spinajs/log-common");
|
|
11
11
|
const di_1 = require("@spinajs/di");
|
|
12
12
|
const LogTarget_1 = require("./LogTarget");
|
|
13
13
|
const __1 = require("..");
|
|
14
|
-
|
|
15
|
-
const colors = require('colors/safe');
|
|
14
|
+
const colors = require("colors/safe");
|
|
16
15
|
exports.DEFAULT_THEME = {
|
|
17
|
-
security: [
|
|
18
|
-
fatal:
|
|
19
|
-
error:
|
|
20
|
-
warn:
|
|
21
|
-
success:
|
|
22
|
-
info:
|
|
23
|
-
debug:
|
|
24
|
-
trace:
|
|
16
|
+
security: ["red", "bgBrightWhite"],
|
|
17
|
+
fatal: "red",
|
|
18
|
+
error: "brightRed",
|
|
19
|
+
warn: "yellow",
|
|
20
|
+
success: "green",
|
|
21
|
+
info: "white",
|
|
22
|
+
debug: "gray",
|
|
23
|
+
trace: "gray",
|
|
25
24
|
};
|
|
26
25
|
let ColoredConsoleTarget = class ColoredConsoleTarget extends LogTarget_1.LogTarget {
|
|
27
26
|
constructor() {
|
|
@@ -37,16 +36,21 @@ let ColoredConsoleTarget = class ColoredConsoleTarget extends LogTarget_1.LogTar
|
|
|
37
36
|
[__1.LogLevel.Warn]: console.warn,
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
|
-
resolve(
|
|
39
|
+
resolve() {
|
|
41
40
|
var _a;
|
|
42
41
|
colors.setTheme((_a = this.Options.theme) !== null && _a !== void 0 ? _a : exports.DEFAULT_THEME);
|
|
43
|
-
super.resolve(
|
|
42
|
+
super.resolve();
|
|
44
43
|
}
|
|
45
44
|
async write(data) {
|
|
46
45
|
if (!this.Options.enabled) {
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
|
-
this.StdConsoleCallbackMap[data.Level](
|
|
48
|
+
this.StdConsoleCallbackMap[data.Level](
|
|
49
|
+
/**
|
|
50
|
+
* we are safe to call, disable eslint
|
|
51
|
+
*/
|
|
52
|
+
/* eslint-disable */
|
|
53
|
+
colors[log_common_1.LogLevelStrings[data.Level]](this.format(data.Variables, this.Options.layout)));
|
|
50
54
|
}
|
|
51
55
|
};
|
|
52
56
|
ColoredConsoleTarget = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColoredConsoleTarget.js","sourceRoot":"","sources":["../../src/targets/ColoredConsoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"ColoredConsoleTarget.js","sourceRoot":"","sources":["../../src/targets/ColoredConsoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAI6B;AAC7B,oCAAoD;AACpD,2CAAwC;AACxC,0BAA8B;AAC9B,sCAAsC;AAEzB,QAAA,aAAa,GAAG;IAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC;IAClC,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,MAAM;CACd,CAAC;AAIF,IAAa,oBAAoB,GAAjC,MAAa,oBAAqB,SAAQ,qBAAuC;IAAjF;;QACY,0BAAqB,GAAG;YAChC,CAAC,YAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,K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FileTargetOptions,
|
|
2
|
+
import { IFileTargetOptions, ILogEntry } from "@spinajs/log-common";
|
|
4
3
|
import { Job } from "node-schedule";
|
|
5
4
|
export declare class FileTarget extends LogTarget<IFileTargetOptions> {
|
|
6
5
|
protected LogDirPath: string;
|
|
@@ -15,8 +14,8 @@ export declare class FileTarget extends LogTarget<IFileTargetOptions> {
|
|
|
15
14
|
protected CurrentFileSize: number;
|
|
16
15
|
protected BufferSize: number;
|
|
17
16
|
protected Buffer: any[];
|
|
18
|
-
resolve(
|
|
19
|
-
write(data:
|
|
17
|
+
resolve(): void;
|
|
18
|
+
write(data: ILogEntry): Promise<void>;
|
|
20
19
|
protected archive(): void;
|
|
21
20
|
protected flush(): void;
|
|
22
21
|
private rotate;
|
|
@@ -1,68 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
2
|
+
/* eslint security/detect-non-literal-fs-filename:0 -- Safe as no value holds user input */
|
|
14
3
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
15
4
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
5
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
6
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
7
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
8
|
};
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
-
if (mod && mod.__esModule) return mod;
|
|
22
|
-
var result = {};
|
|
23
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
-
__setModuleDefault(result, mod);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
-
};
|
|
30
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
10
|
exports.FileTarget = void 0;
|
|
32
11
|
const di_1 = require("@spinajs/di");
|
|
33
12
|
const LogTarget_1 = require("./LogTarget");
|
|
34
|
-
const
|
|
35
|
-
const
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const path = require("path");
|
|
36
15
|
const node_schedule_1 = require("node-schedule");
|
|
37
16
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
38
17
|
const os_1 = require("os");
|
|
39
|
-
const glob =
|
|
40
|
-
const zlib =
|
|
18
|
+
const glob = require("glob");
|
|
19
|
+
const zlib = require("zlib");
|
|
41
20
|
let FileTarget = class FileTarget extends LogTarget_1.LogTarget {
|
|
42
21
|
constructor() {
|
|
43
22
|
super(...arguments);
|
|
44
23
|
this.BufferSize = 0;
|
|
45
24
|
this.Buffer = [];
|
|
46
25
|
}
|
|
47
|
-
resolve(
|
|
26
|
+
resolve() {
|
|
48
27
|
this.Options.options = Object.assign({
|
|
49
28
|
compress: true,
|
|
50
29
|
maxSize: 1024 * 1024,
|
|
51
30
|
maxArchiveFiles: 5,
|
|
52
31
|
bufferSize: 8 * 1024,
|
|
53
|
-
flushTimeout: 10 * 1000
|
|
32
|
+
flushTimeout: 10 * 1000,
|
|
54
33
|
}, this.Options.options);
|
|
55
34
|
this.initialize();
|
|
56
35
|
this.rotate();
|
|
57
36
|
process.on("exit", () => {
|
|
58
37
|
this.flush();
|
|
59
38
|
if (this.LogFileDescriptor) {
|
|
60
|
-
|
|
39
|
+
fs.closeSync(this.LogFileDescriptor);
|
|
61
40
|
}
|
|
62
41
|
});
|
|
63
|
-
super.resolve(
|
|
42
|
+
super.resolve();
|
|
64
43
|
}
|
|
65
|
-
|
|
44
|
+
write(data) {
|
|
66
45
|
if (!this.Options.enabled) {
|
|
67
46
|
return;
|
|
68
47
|
}
|
|
@@ -78,60 +57,57 @@ let FileTarget = class FileTarget extends LogTarget_1.LogTarget {
|
|
|
78
57
|
}
|
|
79
58
|
}
|
|
80
59
|
archive() {
|
|
81
|
-
const files = glob
|
|
60
|
+
const files = glob
|
|
61
|
+
.sync(path.join(this.ArchiveDirPath, `archived_${this.LogBaseName}*{${this.LogFileExt},.gzip}`))
|
|
62
|
+
.map((f) => {
|
|
82
63
|
return {
|
|
83
64
|
name: f,
|
|
84
|
-
stat:
|
|
65
|
+
stat: fs.statSync(f),
|
|
85
66
|
};
|
|
86
|
-
})
|
|
67
|
+
})
|
|
68
|
+
.sort((x) => x.stat.mtime.getTime());
|
|
87
69
|
const newestFile = files.length !== 0 ? files[files.length - 1].name : undefined;
|
|
88
|
-
const fIndex = newestFile
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
70
|
+
const fIndex = newestFile
|
|
71
|
+
? parseInt(newestFile.substring(newestFile.lastIndexOf("_") + 1, newestFile.lastIndexOf("_") + 2), 10) + 1
|
|
72
|
+
: 1;
|
|
73
|
+
const archPath = path.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}`);
|
|
74
|
+
this.flush();
|
|
75
|
+
if (!fs.existsSync(this.LogPath)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
fs.closeSync(this.LogFileDescriptor);
|
|
79
|
+
fs.copyFileSync(this.LogPath, archPath);
|
|
80
|
+
fs.unlinkSync(this.LogPath);
|
|
81
|
+
this.initialize();
|
|
82
|
+
if (this.Options.options.compress) {
|
|
83
|
+
const zippedPath = path.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}.gzip`);
|
|
84
|
+
const zip = zlib.createGzip();
|
|
85
|
+
const read = fs.createReadStream(archPath);
|
|
86
|
+
const write = fs.createWriteStream(zippedPath);
|
|
87
|
+
read.pipe(zip).pipe(write);
|
|
88
|
+
write.on("finish", () => {
|
|
89
|
+
read.close();
|
|
90
|
+
zip.close();
|
|
91
|
+
write.close();
|
|
92
|
+
fs.unlink(archPath, () => {
|
|
93
|
+
return;
|
|
110
94
|
});
|
|
111
|
-
}
|
|
112
|
-
if (files.length >= this.Options.options.maxArchiveFiles) {
|
|
113
|
-
fs_1.default.unlink(files[0].name, () => { return; });
|
|
114
|
-
}
|
|
95
|
+
});
|
|
115
96
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
97
|
+
if (files.length >= this.Options.options.maxArchiveFiles) {
|
|
98
|
+
fs.unlink(files[0].name, () => {
|
|
99
|
+
return;
|
|
100
|
+
});
|
|
119
101
|
}
|
|
120
102
|
}
|
|
121
103
|
flush() {
|
|
122
104
|
if (!this.LogFileDescriptor || this.HasError || this.BufferSize === 0) {
|
|
123
105
|
return;
|
|
124
106
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.BufferSize = 0;
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
this.HasError = true;
|
|
133
|
-
this.Error = err;
|
|
134
|
-
}
|
|
107
|
+
fs.writeFileSync(this.LogFileDescriptor, this.Buffer.join());
|
|
108
|
+
this.CurrentFileSize += this.BufferSize;
|
|
109
|
+
this.Buffer = [];
|
|
110
|
+
this.BufferSize = 0;
|
|
135
111
|
}
|
|
136
112
|
rotate() {
|
|
137
113
|
if (this.Options.options.rotate) {
|
|
@@ -141,48 +117,44 @@ let FileTarget = class FileTarget extends LogTarget_1.LogTarget {
|
|
|
141
117
|
}
|
|
142
118
|
}
|
|
143
119
|
initialize() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
if (fs_1.default.existsSync(this.LogPath)) {
|
|
170
|
-
const { size } = fs_1.default.statSync(this.LogPath);
|
|
171
|
-
this.CurrentFileSize = size;
|
|
172
|
-
}
|
|
173
|
-
this.LogFileDescriptor = fs_1.default.openSync(this.LogPath, "a");
|
|
174
|
-
if (this.Options.options.flushTimeout !== 0) {
|
|
175
|
-
setTimeout(() => {
|
|
176
|
-
this.flush();
|
|
177
|
-
}, this.Options.options.flushTimeout);
|
|
120
|
+
this.flush();
|
|
121
|
+
if (this.LogFileDescriptor >= 0) {
|
|
122
|
+
fs.closeSync(this.LogFileDescriptor);
|
|
123
|
+
this.LogFileDescriptor = 0;
|
|
124
|
+
}
|
|
125
|
+
this.CurrentFileSize = 0;
|
|
126
|
+
this.LogDirPath = this.format(null, path.dirname(path.resolve(this.Options.options.path)));
|
|
127
|
+
this.ArchiveDirPath = this.Options.options.archivePath
|
|
128
|
+
? this.format(null, path.resolve(this.Options.options.archivePath))
|
|
129
|
+
: this.LogDirPath;
|
|
130
|
+
this.LogFileName = this.format(null, path.basename(this.Options.options.path));
|
|
131
|
+
this.LogPath = path.join(this.LogDirPath, this.LogFileName);
|
|
132
|
+
const { name, ext } = path.parse(this.LogFileName);
|
|
133
|
+
this.LogFileExt = ext;
|
|
134
|
+
this.LogBaseName = name;
|
|
135
|
+
if (!this.LogDirPath) {
|
|
136
|
+
throw new exceptions_1.InvalidOption("Missing LogDirPath log option");
|
|
137
|
+
}
|
|
138
|
+
if (!fs.existsSync(this.LogDirPath)) {
|
|
139
|
+
fs.mkdirSync(this.LogDirPath);
|
|
140
|
+
}
|
|
141
|
+
if (this.ArchiveDirPath) {
|
|
142
|
+
if (!fs.existsSync(this.ArchiveDirPath)) {
|
|
143
|
+
fs.mkdirSync(this.ArchiveDirPath);
|
|
178
144
|
}
|
|
179
|
-
this.HasError = false;
|
|
180
|
-
this.Error = null;
|
|
181
145
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
this.
|
|
146
|
+
if (fs.existsSync(this.LogPath)) {
|
|
147
|
+
const { size } = fs.statSync(this.LogPath);
|
|
148
|
+
this.CurrentFileSize = size;
|
|
149
|
+
}
|
|
150
|
+
this.LogFileDescriptor = fs.openSync(this.LogPath, "a");
|
|
151
|
+
if (this.Options.options.flushTimeout !== 0) {
|
|
152
|
+
setTimeout(() => {
|
|
153
|
+
this.flush();
|
|
154
|
+
}, this.Options.options.flushTimeout);
|
|
185
155
|
}
|
|
156
|
+
this.HasError = false;
|
|
157
|
+
this.Error = null;
|
|
186
158
|
}
|
|
187
159
|
};
|
|
188
160
|
FileTarget = __decorate([
|