@spinajs/log 1.0.9 → 1.1.5
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/config/log.d.ts +9 -0
- package/lib/config/log.js +16 -0
- package/lib/config/log.js.map +1 -0
- package/lib/decorators.d.ts +6 -0
- package/lib/decorators.js +37 -0
- package/lib/decorators.js.map +1 -0
- package/lib/index.d.ts +5 -227
- package/lib/index.js +7 -200
- package/lib/index.js.map +1 -1
- package/lib/log.d.ts +70 -0
- package/lib/log.js +218 -0
- package/lib/log.js.map +1 -0
- package/lib/logger.d.ts +8 -0
- package/lib/logger.js +40 -0
- package/lib/logger.js.map +1 -0
- package/lib/schemas/log.configuration.d.ts +115 -0
- package/lib/schemas/log.configuration.js +136 -0
- package/lib/schemas/log.configuration.js.map +1 -0
- package/lib/targets/BlackHoleTarget.d.ts +8 -0
- package/lib/targets/BlackHoleTarget.js +25 -0
- package/lib/targets/BlackHoleTarget.js.map +1 -0
- package/lib/targets/ColoredConsoleTarget.d.ts +51 -0
- package/lib/targets/ColoredConsoleTarget.js +57 -0
- package/lib/targets/ColoredConsoleTarget.js.map +1 -0
- package/lib/targets/FileTarget.d.ts +24 -0
- package/lib/targets/FileTarget.js +193 -0
- package/lib/targets/FileTarget.js.map +1 -0
- package/lib/targets/LogTarget.d.ts +14 -0
- package/lib/targets/LogTarget.js +79 -0
- package/lib/targets/LogTarget.js.map +1 -0
- package/lib/targets/index.d.ts +3 -0
- package/lib/targets/index.js +16 -0
- package/lib/targets/index.js.map +1 -0
- package/lib/types.d.ts +145 -0
- package/lib/types.js +38 -0
- package/lib/types.js.map +1 -0
- package/lib/variables/date.d.ts +17 -0
- package/lib/variables/date.js +62 -0
- package/lib/variables/date.js.map +1 -0
- package/lib/variables/env.d.ts +5 -0
- package/lib/variables/env.js +25 -0
- package/lib/variables/env.js.map +1 -0
- package/lib/variables/index.d.ts +3 -0
- package/lib/variables/index.js +16 -0
- package/lib/variables/index.js.map +1 -0
- package/lib/variables/process.d.ts +6 -0
- package/lib/variables/process.js +36 -0
- package/lib/variables/process.js.map +1 -0
- package/package.json +21 -8
- package/yarn-error.log +2304 -13
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ColoredConsoleTarget = exports.DEFAULT_THEME = void 0;
|
|
10
|
+
const types_1 = require("./../types");
|
|
11
|
+
const di_1 = require("@spinajs/di");
|
|
12
|
+
const LogTarget_1 = require("./LogTarget");
|
|
13
|
+
const __1 = require("..");
|
|
14
|
+
// tslint:disable-next-line
|
|
15
|
+
const colors = require('colors/safe');
|
|
16
|
+
exports.DEFAULT_THEME = {
|
|
17
|
+
security: ['red', "bgBrightWhite"],
|
|
18
|
+
fatal: 'red',
|
|
19
|
+
error: 'brightRed',
|
|
20
|
+
warn: 'yellow',
|
|
21
|
+
success: 'green',
|
|
22
|
+
info: 'white',
|
|
23
|
+
debug: 'gray',
|
|
24
|
+
trace: 'gray',
|
|
25
|
+
};
|
|
26
|
+
let ColoredConsoleTarget = class ColoredConsoleTarget extends LogTarget_1.LogTarget {
|
|
27
|
+
constructor() {
|
|
28
|
+
super(...arguments);
|
|
29
|
+
this.StdConsoleCallbackMap = {
|
|
30
|
+
[__1.LogLevel.Error]: console.error,
|
|
31
|
+
[__1.LogLevel.Fatal]: console.error,
|
|
32
|
+
[__1.LogLevel.Security]: console.error,
|
|
33
|
+
[__1.LogLevel.Info]: console.log,
|
|
34
|
+
[__1.LogLevel.Success]: console.log,
|
|
35
|
+
[__1.LogLevel.Trace]: console.debug,
|
|
36
|
+
[__1.LogLevel.Debug]: console.debug,
|
|
37
|
+
[__1.LogLevel.Warn]: console.warn,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
resolve(_) {
|
|
41
|
+
var _a;
|
|
42
|
+
colors.setTheme((_a = this.Options.theme) !== null && _a !== void 0 ? _a : exports.DEFAULT_THEME);
|
|
43
|
+
super.resolve(_);
|
|
44
|
+
}
|
|
45
|
+
async write(data) {
|
|
46
|
+
if (!this.Options.enabled) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.StdConsoleCallbackMap[data.Level](colors[types_1.LogLevelStrings[data.Level]](this.format(data.Variables, this.Options.layout)));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
ColoredConsoleTarget = __decorate([
|
|
53
|
+
(0, di_1.Singleton)(),
|
|
54
|
+
(0, di_1.Injectable)("ConsoleTarget")
|
|
55
|
+
], ColoredConsoleTarget);
|
|
56
|
+
exports.ColoredConsoleTarget = ColoredConsoleTarget;
|
|
57
|
+
//# sourceMappingURL=ColoredConsoleTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColoredConsoleTarget.js","sourceRoot":"","sources":["../../src/targets/ColoredConsoleTarget.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAA2F;AAC3F,oCAAgE;AAChE,2CAAwC;AACxC,0BAA8B;AAE9B,2BAA2B;AAC3B,MAAM,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEzB,QAAA,aAAa,GAAG;IACzB,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC;IAClC,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,QAAQ;IAC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,CAAC;CACJ,CAAA;AA7BY,oBAAoB;IAFhC,IAAA,cAAS,GAAE;IACX,IAAA,eAAU,EAAC,eAAe,CAAC;GACf,oBAAoB,CA6BhC;AA7BY,oDAAoB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IContainer } from "@spinajs/di";
|
|
2
|
+
import { LogTarget } from "./LogTarget";
|
|
3
|
+
import { IFileTargetOptions, ILogTargetData } from "../types";
|
|
4
|
+
import { Job } from "node-schedule";
|
|
5
|
+
export declare class FileTarget extends LogTarget<IFileTargetOptions> {
|
|
6
|
+
protected LogDirPath: string;
|
|
7
|
+
protected LogFileName: string;
|
|
8
|
+
protected LogPath: string;
|
|
9
|
+
protected LogFileExt: string;
|
|
10
|
+
protected LogBaseName: string;
|
|
11
|
+
protected ArchiveDirPath: string;
|
|
12
|
+
protected RotateJob: Job;
|
|
13
|
+
protected ArchiveJob: Job;
|
|
14
|
+
protected LogFileDescriptor: number;
|
|
15
|
+
protected CurrentFileSize: number;
|
|
16
|
+
protected BufferSize: number;
|
|
17
|
+
protected Buffer: any[];
|
|
18
|
+
resolve(_: IContainer): void;
|
|
19
|
+
write(data: ILogTargetData): Promise<void>;
|
|
20
|
+
protected archive(): void;
|
|
21
|
+
protected flush(): void;
|
|
22
|
+
private rotate;
|
|
23
|
+
private initialize;
|
|
24
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
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
|
+
});
|
|
14
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
};
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.FileTarget = void 0;
|
|
32
|
+
const di_1 = require("@spinajs/di");
|
|
33
|
+
const LogTarget_1 = require("./LogTarget");
|
|
34
|
+
const fs_1 = __importDefault(require("fs"));
|
|
35
|
+
const path_1 = __importDefault(require("path"));
|
|
36
|
+
const node_schedule_1 = require("node-schedule");
|
|
37
|
+
const exceptions_1 = require("@spinajs/exceptions");
|
|
38
|
+
const os_1 = require("os");
|
|
39
|
+
const glob = __importStar(require("glob"));
|
|
40
|
+
const zlib = __importStar(require("zlib"));
|
|
41
|
+
let FileTarget = class FileTarget extends LogTarget_1.LogTarget {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.BufferSize = 0;
|
|
45
|
+
this.Buffer = [];
|
|
46
|
+
}
|
|
47
|
+
resolve(_) {
|
|
48
|
+
this.Options.options = Object.assign({
|
|
49
|
+
compress: true,
|
|
50
|
+
maxSize: 1024 * 1024,
|
|
51
|
+
maxArchiveFiles: 5,
|
|
52
|
+
bufferSize: 8 * 1024,
|
|
53
|
+
flushTimeout: 10 * 1000
|
|
54
|
+
}, this.Options.options);
|
|
55
|
+
this.initialize();
|
|
56
|
+
this.rotate();
|
|
57
|
+
process.on("exit", () => {
|
|
58
|
+
this.flush();
|
|
59
|
+
if (this.LogFileDescriptor) {
|
|
60
|
+
fs_1.default.closeSync(this.LogFileDescriptor);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
super.resolve(_);
|
|
64
|
+
}
|
|
65
|
+
async write(data) {
|
|
66
|
+
if (!this.Options.enabled) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const result = this.format(data.Variables, this.Options.layout) + os_1.EOL;
|
|
70
|
+
const bytes = Buffer.byteLength(result);
|
|
71
|
+
this.BufferSize += bytes;
|
|
72
|
+
this.Buffer.push(result);
|
|
73
|
+
if (this.BufferSize > this.Options.options.bufferSize) {
|
|
74
|
+
this.flush();
|
|
75
|
+
}
|
|
76
|
+
if (this.CurrentFileSize > this.Options.options.maxSize) {
|
|
77
|
+
this.archive();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
archive() {
|
|
81
|
+
const files = glob.sync(path_1.default.join(this.ArchiveDirPath, `archived_${this.LogBaseName}*{${this.LogFileExt},.gzip}`)).map(f => {
|
|
82
|
+
return {
|
|
83
|
+
name: f,
|
|
84
|
+
stat: fs_1.default.statSync(f)
|
|
85
|
+
};
|
|
86
|
+
}).sort(x => x.stat.mtime.getTime());
|
|
87
|
+
const newestFile = files.length !== 0 ? files[files.length - 1].name : undefined;
|
|
88
|
+
const fIndex = newestFile ? parseInt(newestFile.substring(newestFile.lastIndexOf("_") + 1, newestFile.lastIndexOf("_") + 2), 10) + 1 : 1;
|
|
89
|
+
const archPath = path_1.default.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}`);
|
|
90
|
+
try {
|
|
91
|
+
this.flush();
|
|
92
|
+
if (!fs_1.default.existsSync(this.LogPath)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
fs_1.default.closeSync(this.LogFileDescriptor);
|
|
96
|
+
fs_1.default.copyFileSync(this.LogPath, archPath);
|
|
97
|
+
fs_1.default.unlinkSync(this.LogPath);
|
|
98
|
+
this.initialize();
|
|
99
|
+
if (this.Options.options.compress) {
|
|
100
|
+
const zippedPath = path_1.default.join(this.ArchiveDirPath, `archived_${this.LogBaseName}_${fIndex}${this.LogFileExt}.gzip`);
|
|
101
|
+
const zip = zlib.createGzip();
|
|
102
|
+
const read = fs_1.default.createReadStream(archPath);
|
|
103
|
+
const write = fs_1.default.createWriteStream(zippedPath);
|
|
104
|
+
read.pipe(zip).pipe(write);
|
|
105
|
+
write.on("finish", () => {
|
|
106
|
+
read.close();
|
|
107
|
+
zip.close();
|
|
108
|
+
write.close();
|
|
109
|
+
fs_1.default.unlink(archPath, () => { return; });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (files.length >= this.Options.options.maxArchiveFiles) {
|
|
113
|
+
fs_1.default.unlink(files[0].name, () => { return; });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
this.Error = err;
|
|
118
|
+
this.HasError = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
flush() {
|
|
122
|
+
if (!this.LogFileDescriptor || this.HasError || this.BufferSize === 0) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
fs_1.default.writeFileSync(this.LogFileDescriptor, this.Buffer.join());
|
|
127
|
+
this.CurrentFileSize += this.BufferSize;
|
|
128
|
+
this.Buffer = [];
|
|
129
|
+
this.BufferSize = 0;
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
this.HasError = true;
|
|
133
|
+
this.Error = err;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
rotate() {
|
|
137
|
+
if (this.Options.options.rotate) {
|
|
138
|
+
this.RotateJob = (0, node_schedule_1.scheduleJob)(`LogScheduleJob`, this.Options.options.rotate, () => {
|
|
139
|
+
this.archive();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
initialize() {
|
|
144
|
+
try {
|
|
145
|
+
this.flush();
|
|
146
|
+
if (this.LogFileDescriptor >= 0) {
|
|
147
|
+
fs_1.default.closeSync(this.LogFileDescriptor);
|
|
148
|
+
this.LogFileDescriptor = 0;
|
|
149
|
+
}
|
|
150
|
+
this.CurrentFileSize = 0;
|
|
151
|
+
this.LogDirPath = this.format({}, path_1.default.dirname(path_1.default.resolve(this.Options.options.path)));
|
|
152
|
+
this.ArchiveDirPath = this.Options.options.archivePath ? this.format({}, path_1.default.resolve(this.Options.options.archivePath)) : this.LogDirPath;
|
|
153
|
+
this.LogFileName = this.format({}, path_1.default.basename(this.Options.options.path));
|
|
154
|
+
this.LogPath = path_1.default.join(this.LogDirPath, this.LogFileName);
|
|
155
|
+
const { name, ext } = path_1.default.parse(this.LogFileName);
|
|
156
|
+
this.LogFileExt = ext;
|
|
157
|
+
this.LogBaseName = name;
|
|
158
|
+
if (!this.LogDirPath) {
|
|
159
|
+
throw new exceptions_1.InvalidOption("Missing LogDirPath log option");
|
|
160
|
+
}
|
|
161
|
+
if (!fs_1.default.existsSync(this.LogDirPath)) {
|
|
162
|
+
fs_1.default.mkdirSync(this.LogDirPath);
|
|
163
|
+
}
|
|
164
|
+
if (this.ArchiveDirPath) {
|
|
165
|
+
if (!fs_1.default.existsSync(this.ArchiveDirPath)) {
|
|
166
|
+
fs_1.default.mkdirSync(this.ArchiveDirPath);
|
|
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);
|
|
178
|
+
}
|
|
179
|
+
this.HasError = false;
|
|
180
|
+
this.Error = null;
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
this.HasError = true;
|
|
184
|
+
this.Error = err;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
FileTarget = __decorate([
|
|
189
|
+
(0, di_1.Injectable)("FileTarget"),
|
|
190
|
+
(0, di_1.NewInstance)()
|
|
191
|
+
], FileTarget);
|
|
192
|
+
exports.FileTarget = FileTarget;
|
|
193
|
+
//# sourceMappingURL=FileTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileTarget.js","sourceRoot":"","sources":["../../src/targets/FileTarget.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAkE;AAClE,2CAAwC;AAExC,4CAAoB;AACpB,gDAAwB;AACxB,iDAAiD;AACjD,oDAAoD;AACpD,2BAAyB;AACzB,2CAA6B;AAC7B,2CAA6B;AAI7B,IAAa,UAAU,GAAvB,MAAa,UAAW,SAAQ,qBAA6B;IAA7D;;QAiBc,eAAU,GAAW,CAAC,CAAC;QAEvB,WAAM,GAAU,EAAE,CAAC;IA8LjC,CAAC;IA3LU,OAAO,CAAC,CAAa;QAExB,IAAI,CAAC,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;YACjC,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,IAAI,GAAG,IAAI;YACpB,e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AC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAC3C,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;aAC/B;YAED,IAAI,CAAC,iBAAiB,GAAG,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAExD,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,KAAK,CAAC,EAAE;gBACzC,UAAU,CAAC,GAAG,EAAE;oBACZ,IAAI,CAAC,KAAK,EAAE,CAAC;gBACjB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;aACxC;YAED,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;SACrB;QAAC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;SACpB;IAEL,CAAC;CAEJ,CAAA;AAjNY,UAAU;IAFtB,IAAA,eAAU,EAAC,YAAY,CAAC;IACxB,IAAA,gBAAW,GAAE;GACD,UAAU,CAiNtB;AAjNY,gCAAU"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ICommonTargetOptions } from './../types';
|
|
2
|
+
import { SyncModule } from "@spinajs/di";
|
|
3
|
+
import { LogVariable, ILogTargetData } from "../types";
|
|
4
|
+
export declare abstract class LogTarget<T extends ICommonTargetOptions> extends SyncModule {
|
|
5
|
+
protected Variables: LogVariable[];
|
|
6
|
+
HasError: boolean;
|
|
7
|
+
Error: Error | null;
|
|
8
|
+
protected VariablesDictionary: Map<string, LogVariable>;
|
|
9
|
+
protected LayoutRegexp: RegExp;
|
|
10
|
+
protected Options: T;
|
|
11
|
+
constructor(Variables: LogVariable[], options: T);
|
|
12
|
+
abstract write(data: ILogTargetData): Promise<void>;
|
|
13
|
+
protected format(customVars: {}, layout: string): string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.LogTarget = void 0;
|
|
16
|
+
const di_1 = require("@spinajs/di");
|
|
17
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
18
|
+
const types_1 = require("../types");
|
|
19
|
+
let LogTarget = class LogTarget extends di_1.SyncModule {
|
|
20
|
+
constructor(Variables, options) {
|
|
21
|
+
super();
|
|
22
|
+
this.Variables = Variables;
|
|
23
|
+
this.HasError = false;
|
|
24
|
+
this.Error = null;
|
|
25
|
+
this.VariablesDictionary = new Map();
|
|
26
|
+
this.Variables.forEach(v => {
|
|
27
|
+
this.VariablesDictionary.set(v.Name, v);
|
|
28
|
+
});
|
|
29
|
+
this.LayoutRegexp = /\{((.*?)(:(.*?))?)\}/gm;
|
|
30
|
+
if (options) {
|
|
31
|
+
this.Options = lodash_1.default.merge(lodash_1.default.merge(this.Options, {
|
|
32
|
+
enabled: true,
|
|
33
|
+
layout: "{datetime} {level} {message} {error} ({logger})"
|
|
34
|
+
}), options);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
format(customVars, layout) {
|
|
38
|
+
const self = this;
|
|
39
|
+
if (customVars.message) {
|
|
40
|
+
return _format(Object.assign(Object.assign({}, customVars), { message: _format(customVars, customVars.message) }), layout);
|
|
41
|
+
}
|
|
42
|
+
return _format(customVars, layout);
|
|
43
|
+
function _format(vars, txt) {
|
|
44
|
+
self.LayoutRegexp.lastIndex = 0;
|
|
45
|
+
const varMatch = [...txt.matchAll(self.LayoutRegexp)];
|
|
46
|
+
if (!varMatch) {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
let result = txt;
|
|
50
|
+
varMatch.forEach(v => {
|
|
51
|
+
if (vars[v[2]]) {
|
|
52
|
+
result = result.replace(v[0], vars[v[2]]);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const variable = self.VariablesDictionary.get(v[2]);
|
|
56
|
+
if (variable) {
|
|
57
|
+
// optional parameter eg. {env:PORT}
|
|
58
|
+
if (v[3]) {
|
|
59
|
+
result = result.replace(v[0], variable.Value(v[4]));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
result = result.replace(v[0], variable.Value());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
result = result.replace(v[0], "");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
LogTarget = __decorate([
|
|
75
|
+
(0, di_1.Inject)(Array.ofType(types_1.LogVariable)),
|
|
76
|
+
__metadata("design:paramtypes", [Array, Object])
|
|
77
|
+
], LogTarget);
|
|
78
|
+
exports.LogTarget = LogTarget;
|
|
79
|
+
//# sourceMappingURL=LogTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogTarget.js","sourceRoot":"","sources":["../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|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./ColoredConsoleTarget"), exports);
|
|
14
|
+
__exportStar(require("./FileTarget"), exports);
|
|
15
|
+
__exportStar(require("./LogTarget"), exports);
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/targets/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAuC;AACvC,+CAA6B;AAC7B,8CAA4B"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
Security = 999,
|
|
3
|
+
Fatal = 6,
|
|
4
|
+
Error = 5,
|
|
5
|
+
Warn = 4,
|
|
6
|
+
Success = 3,
|
|
7
|
+
Info = 2,
|
|
8
|
+
Debug = 1,
|
|
9
|
+
Trace = 0
|
|
10
|
+
}
|
|
11
|
+
export declare const StrToLogLevel: {
|
|
12
|
+
trace: LogLevel;
|
|
13
|
+
debug: LogLevel;
|
|
14
|
+
info: LogLevel;
|
|
15
|
+
success: LogLevel;
|
|
16
|
+
warn: LogLevel;
|
|
17
|
+
error: LogLevel;
|
|
18
|
+
fatal: LogLevel;
|
|
19
|
+
security: LogLevel;
|
|
20
|
+
};
|
|
21
|
+
export declare const LogLevelStrings: {
|
|
22
|
+
1: string;
|
|
23
|
+
5: string;
|
|
24
|
+
6: string;
|
|
25
|
+
2: string;
|
|
26
|
+
999: string;
|
|
27
|
+
3: string;
|
|
28
|
+
0: string;
|
|
29
|
+
4: string;
|
|
30
|
+
};
|
|
31
|
+
export declare abstract class LogVariable {
|
|
32
|
+
abstract get Name(): string;
|
|
33
|
+
abstract Value(option?: string): string;
|
|
34
|
+
}
|
|
35
|
+
export interface ILogRule {
|
|
36
|
+
name: string;
|
|
37
|
+
level: "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "security" | "success";
|
|
38
|
+
target: string | string[];
|
|
39
|
+
}
|
|
40
|
+
export interface ITargetsOption {
|
|
41
|
+
name: string;
|
|
42
|
+
type: string;
|
|
43
|
+
options: ICommonTargetOptions;
|
|
44
|
+
}
|
|
45
|
+
export interface ILogOptions {
|
|
46
|
+
targets: ITargetsOption[];
|
|
47
|
+
rules: ILogRule[];
|
|
48
|
+
variables: {};
|
|
49
|
+
}
|
|
50
|
+
export interface ICommonTargetOptions {
|
|
51
|
+
/**
|
|
52
|
+
* Message layout. You can use variables
|
|
53
|
+
*
|
|
54
|
+
* Default message layout is: {datetime} {level} {message} ({logger})
|
|
55
|
+
*/
|
|
56
|
+
layout: string;
|
|
57
|
+
/**
|
|
58
|
+
* Target name
|
|
59
|
+
*/
|
|
60
|
+
name: string;
|
|
61
|
+
/**
|
|
62
|
+
* Target type
|
|
63
|
+
*/
|
|
64
|
+
type: string;
|
|
65
|
+
/**
|
|
66
|
+
* Is logger enabled
|
|
67
|
+
*/
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface IBlackHoleTargetOptions extends ICommonTargetOptions {
|
|
71
|
+
}
|
|
72
|
+
export interface IColoredConsoleTargetOptions extends ICommonTargetOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Color theme for console message. Best leave it for default.
|
|
75
|
+
*/
|
|
76
|
+
theme: {
|
|
77
|
+
security: string | string[];
|
|
78
|
+
fatal: string | string[];
|
|
79
|
+
error: string | string[];
|
|
80
|
+
warn: string | string[];
|
|
81
|
+
success: string | string[];
|
|
82
|
+
info: string | string[];
|
|
83
|
+
debug: string | string[];
|
|
84
|
+
trace: string | string[];
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export interface IFileTargetOptions extends ICommonTargetOptions {
|
|
88
|
+
options: {
|
|
89
|
+
/**
|
|
90
|
+
* path whre log is stored. It is allowed to use variables to create path eg. date / time etc.
|
|
91
|
+
*/
|
|
92
|
+
path: string;
|
|
93
|
+
/**
|
|
94
|
+
* Archive path for logs eg. when size is exceeded. Is is allowed to use variables eg. date / time etc.
|
|
95
|
+
*
|
|
96
|
+
* Default is none. When not set archive files are stored in same folder as logs.
|
|
97
|
+
*/
|
|
98
|
+
archivePath: string;
|
|
99
|
+
/**
|
|
100
|
+
* Maximum log file size, if exceeded it is moved to archive, and new log file is created
|
|
101
|
+
*
|
|
102
|
+
* Default is 1mb
|
|
103
|
+
*/
|
|
104
|
+
maxSize: number;
|
|
105
|
+
/**
|
|
106
|
+
* Should compress log file when moved to archive
|
|
107
|
+
*
|
|
108
|
+
* Default is false
|
|
109
|
+
*/
|
|
110
|
+
compress: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Should rotate log file eg. new file every new day.
|
|
113
|
+
* You should use cron like definition eg. at 1am every day: 0 1 * * *
|
|
114
|
+
* When rotate event occurs, old file is moved to archive, and new one is created
|
|
115
|
+
*
|
|
116
|
+
* Default is not set
|
|
117
|
+
*/
|
|
118
|
+
rotate: string;
|
|
119
|
+
/**
|
|
120
|
+
* How mutch archive files should be preserved before deletion. Default is 0
|
|
121
|
+
* Eg. to store max 5 archive files, set it to 5. Oldest by modification time are deleted.
|
|
122
|
+
*/
|
|
123
|
+
maxArchiveFiles: number;
|
|
124
|
+
/**
|
|
125
|
+
* Buffer size for incoming log messages. Messages are stored in buffer before write to file.
|
|
126
|
+
*
|
|
127
|
+
* Default is 8kb
|
|
128
|
+
*/
|
|
129
|
+
bufferSize: number;
|
|
130
|
+
/**
|
|
131
|
+
* Time in ms after whitch flush will be forced. If set to 0 feature is disabled ( any data hangin in temp buffer will not be saved before it reaches bufferSize)
|
|
132
|
+
* Default time is 10s.
|
|
133
|
+
*/
|
|
134
|
+
flushTimeout: number;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export interface ILogTargetData {
|
|
138
|
+
Level: LogLevel;
|
|
139
|
+
Variables: {
|
|
140
|
+
error: Error | undefined;
|
|
141
|
+
level: string;
|
|
142
|
+
logger: string;
|
|
143
|
+
message: string;
|
|
144
|
+
};
|
|
145
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogVariable = exports.LogLevelStrings = exports.StrToLogLevel = exports.LogLevel = void 0;
|
|
4
|
+
var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel[LogLevel["Security"] = 999] = "Security";
|
|
7
|
+
LogLevel[LogLevel["Fatal"] = 6] = "Fatal";
|
|
8
|
+
LogLevel[LogLevel["Error"] = 5] = "Error";
|
|
9
|
+
LogLevel[LogLevel["Warn"] = 4] = "Warn";
|
|
10
|
+
LogLevel[LogLevel["Success"] = 3] = "Success";
|
|
11
|
+
LogLevel[LogLevel["Info"] = 2] = "Info";
|
|
12
|
+
LogLevel[LogLevel["Debug"] = 1] = "Debug";
|
|
13
|
+
LogLevel[LogLevel["Trace"] = 0] = "Trace";
|
|
14
|
+
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
|
|
15
|
+
exports.StrToLogLevel = {
|
|
16
|
+
"trace": LogLevel.Trace,
|
|
17
|
+
"debug": LogLevel.Debug,
|
|
18
|
+
"info": LogLevel.Info,
|
|
19
|
+
"success": LogLevel.Success,
|
|
20
|
+
"warn": LogLevel.Warn,
|
|
21
|
+
"error": LogLevel.Error,
|
|
22
|
+
"fatal": LogLevel.Fatal,
|
|
23
|
+
"security": LogLevel.Security
|
|
24
|
+
};
|
|
25
|
+
exports.LogLevelStrings = {
|
|
26
|
+
[LogLevel.Debug]: "debug",
|
|
27
|
+
[LogLevel.Error]: "error",
|
|
28
|
+
[LogLevel.Fatal]: "fatal",
|
|
29
|
+
[LogLevel.Info]: "info",
|
|
30
|
+
[LogLevel.Security]: "security",
|
|
31
|
+
[LogLevel.Success]: "success",
|
|
32
|
+
[LogLevel.Trace]: "trace",
|
|
33
|
+
[LogLevel.Warn]: "warn",
|
|
34
|
+
};
|
|
35
|
+
class LogVariable {
|
|
36
|
+
}
|
|
37
|
+
exports.LogVariable = LogVariable;
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAgBX;AAhBD,WAAY,QAAQ;IAChB,iDAAc,CAAA;IAEd,yCAAS,CAAA;IAET,yCAAS,CAAA;IAET,uCAAQ,CAAA;IAER,6CAAW,CAAA;IAEX,uCAAQ,CAAA;IAER,yCAAS,CAAA;IAET,yCAAS,CAAA;AACb,CAAC,EAhBW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAgBnB;AAEY,QAAA,aAAa,GAAG;IACzB,OAAO,EAAE,QAAQ,CAAC,KAAK;IACvB,OAAO,EAAE,QAAQ,CAAC,KAAK;IACvB,MAAM,EAAE,QAAQ,CAAC,IAAI;IACrB,SAAS,EAAE,QAAQ,CAAC,OAAO;IAC3B,MAAM,EAAE,QAAQ,CAAC,IAAI;IACrB,OAAO,EAAE,QAAQ,CAAC,KAAK;IACvB,OAAO,EAAE,QAAQ,CAAC,KAAK;IACvB,UAAU,EAAE,QAAQ,CAAC,QAAQ;CAChC,CAAA;AAEY,QAAA,eAAe,GAAG;IAC3B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;IACvB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU;IAC/B,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS;IAC7B,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO;IACzB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM;CAC1B,CAAC;AAEF,MAAsB,WAAW;CAGhC;AAHD,kCAGC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LogVariable } from "../types";
|
|
2
|
+
export declare class DateTimeLogVariable extends LogVariable {
|
|
3
|
+
get Name(): string;
|
|
4
|
+
Value(option?: string): string;
|
|
5
|
+
}
|
|
6
|
+
export declare class DateLogVariable extends LogVariable {
|
|
7
|
+
protected format?: string;
|
|
8
|
+
constructor(format?: string);
|
|
9
|
+
get Name(): string;
|
|
10
|
+
Value(option?: string): string;
|
|
11
|
+
}
|
|
12
|
+
export declare class TimeLogVariable extends LogVariable {
|
|
13
|
+
protected format?: string;
|
|
14
|
+
constructor(format?: string);
|
|
15
|
+
get Name(): string;
|
|
16
|
+
Value(option?: string): string;
|
|
17
|
+
}
|