@spinajs/log 2.0.51 → 2.0.53

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.
Files changed (41) hide show
  1. package/lib/bootstrap.d.ts +5 -0
  2. package/lib/bootstrap.d.ts.map +1 -0
  3. package/lib/bootstrap.js +49 -0
  4. package/lib/bootstrap.js.map +1 -0
  5. package/lib/decorators.d.ts +7 -0
  6. package/lib/decorators.d.ts.map +1 -0
  7. package/lib/decorators.js +35 -0
  8. package/lib/decorators.js.map +1 -0
  9. package/lib/index.d.ts +6 -0
  10. package/lib/index.d.ts.map +1 -0
  11. package/lib/index.js +6 -0
  12. package/lib/index.js.map +1 -0
  13. package/lib/log.d.ts +45 -0
  14. package/lib/log.d.ts.map +1 -0
  15. package/lib/log.js +195 -0
  16. package/lib/log.js.map +1 -0
  17. package/lib/schemas/log.configuration.d.ts +88 -0
  18. package/lib/schemas/log.configuration.d.ts.map +1 -0
  19. package/lib/schemas/log.configuration.js +90 -0
  20. package/lib/schemas/log.configuration.js.map +1 -0
  21. package/lib/targets/BlackHoleTarget.d.ts +8 -0
  22. package/lib/targets/BlackHoleTarget.d.ts.map +1 -0
  23. package/lib/targets/BlackHoleTarget.js +22 -0
  24. package/lib/targets/BlackHoleTarget.js.map +1 -0
  25. package/lib/targets/ColoredConsoleTarget.d.ts +51 -0
  26. package/lib/targets/ColoredConsoleTarget.d.ts.map +1 -0
  27. package/lib/targets/ColoredConsoleTarget.js +65 -0
  28. package/lib/targets/ColoredConsoleTarget.js.map +1 -0
  29. package/lib/targets/FileTarget.d.ts +30 -0
  30. package/lib/targets/FileTarget.d.ts.map +1 -0
  31. package/lib/targets/FileTarget.js +224 -0
  32. package/lib/targets/FileTarget.js.map +1 -0
  33. package/lib/targets/index.d.ts +4 -0
  34. package/lib/targets/index.d.ts.map +1 -0
  35. package/lib/targets/index.js +4 -0
  36. package/lib/targets/index.js.map +1 -0
  37. package/package.json +9 -6
  38. package/.eslintignore +0 -2
  39. package/.eslintrc.cjs +0 -45
  40. package/.mocharc.json +0 -8
  41. package/typedoc.json +0 -16
@@ -0,0 +1,5 @@
1
+ import { Bootstrapper } from "@spinajs/di";
2
+ export declare class LogBotstrapper extends Bootstrapper {
3
+ bootstrap(): void;
4
+ }
5
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,YAAY,EAAM,MAAM,aAAa,CAAC;AAI3D,qBACa,cAAe,SAAQ,YAAY;IACvC,SAAS,IAAI,IAAI;CAgCzB"}
@@ -0,0 +1,49 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Configuration } from "@spinajs/configuration";
8
+ import { Injectable, Bootstrapper, DI } from "@spinajs/di";
9
+ import { Log } from "./log.js";
10
+ import CONFIGURATION_SCHEMA from "./schemas/log.configuration.js";
11
+ let LogBotstrapper = class LogBotstrapper extends Bootstrapper {
12
+ bootstrap() {
13
+ DI.register(CONFIGURATION_SCHEMA).asValue("__configurationSchema__");
14
+ // check if we run tests,
15
+ // hook for uncaughtException causes to not showing
16
+ // mocha errors in console
17
+ if (!process.env.TESTING) {
18
+ process.on("uncaughtException", (err) => {
19
+ // if we have configuration resolved, we can assume that logger can read configuration
20
+ // so log to default log
21
+ // if not log to console
22
+ if (DI.has(Configuration)) {
23
+ const log = DI.resolve(Log, ["process"]);
24
+ log.fatal(err, "Unhandled exception occured");
25
+ }
26
+ else {
27
+ console.error("Unhandled exception occured, reason:" + JSON.stringify(err));
28
+ }
29
+ });
30
+ process.on("unhandledRejection", (reason, p) => {
31
+ // if we have configuration resolved, we can assume that logger can read configuration
32
+ // so log to default log
33
+ // if not log to console
34
+ if (DI.has(Configuration)) {
35
+ const log = DI.resolve(Log, ["process"]);
36
+ log.fatal(reason, "Unhandled rejection at Promise %s", p);
37
+ }
38
+ else {
39
+ console.error("Unhandled rejection at Promise %s, reason: " + JSON.stringify(reason));
40
+ }
41
+ });
42
+ }
43
+ }
44
+ };
45
+ LogBotstrapper = __decorate([
46
+ Injectable(Bootstrapper)
47
+ ], LogBotstrapper);
48
+ export { LogBotstrapper };
49
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,oBAAoB,MAAM,gCAAgC,CAAC;AAG3D,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,YAAY;IACvC,SAAS;QACd,EAAE,CAAC,QAAQ,CAAC,oBAAoB,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,sFAAsF;gBACtF,wBAAwB;gBACxB,wBAAwB;gBACxB,IAAI,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;oBACzB,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;oBACzC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,6BAA6B,CAAC,CAAC;iBAC/C;qBAAM;oBACL,OAAO,CAAC,KAAK,CAAC,sCAAsC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;iBAC7E;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC7C,sFAAsF;gBACtF,wBAAwB;gBACxB,wBAAwB;gBACxB,IAAI,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE;oBACzB,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;oBACzC,GAAG,CAAC,KAAK,CAAC,MAAe,EAAE,mCAAmC,EAAE,CAAC,CAAC,CAAC;iBACpE;qBAAM;oBACL,OAAO,CAAC,KAAK,CAAC,6CAA6C,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;iBACvF;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AAjCY,cAAc;IAD1B,UAAU,CAAC,YAAY,CAAC;GACZ,cAAc,CAiC1B;SAjCY,cAAc"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates ( if not exists ) new logger instance with given name and optional variables
3
+ * @param name - name of logger
4
+ * @param variables - optional log variables
5
+ */
6
+ export declare function Logger(name: string, variables?: Record<string, unknown>): (target: any, key: string) => any;
7
+ //# sourceMappingURL=decorators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YACtD,GAAG,OAAO,MAAM,KAAG,GAAG,CAyBvC"}
@@ -0,0 +1,35 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
+ import { DI } from "@spinajs/di";
4
+ import { Log } from "./log.js";
5
+ /**
6
+ * Creates ( if not exists ) new logger instance with given name and optional variables
7
+ * @param name - name of logger
8
+ * @param variables - optional log variables
9
+ */
10
+ export function Logger(name, variables) {
11
+ return (target, key) => {
12
+ let logger;
13
+ // property getter
14
+ const getter = () => {
15
+ if (!logger) {
16
+ const allLoggers = DI.get(Array.ofType(Log));
17
+ const found = allLoggers.find((l) => l.Name);
18
+ if (found) {
19
+ logger = found;
20
+ }
21
+ else {
22
+ logger = DI.resolve(Log, [name, variables]);
23
+ }
24
+ }
25
+ return logger;
26
+ };
27
+ // Create new property with getter and setter
28
+ Object.defineProperty(target, key, {
29
+ get: getter,
30
+ enumerable: false,
31
+ configurable: false,
32
+ });
33
+ };
34
+ }
35
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,SAAmC;IACtE,OAAO,CAAC,MAAW,EAAE,GAAW,EAAO,EAAE;QACvC,IAAI,MAAW,CAAC;QAEhB,kBAAkB;QAClB,MAAM,MAAM,GAAG,GAAG,EAAE;YAClB,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,UAAU,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAE7C,IAAI,KAAK,EAAE;oBACT,MAAM,GAAG,KAAK,CAAC;iBAChB;qBAAM;oBACL,MAAM,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;iBAC7C;aACF;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QAEF,6CAA6C;QAC7C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YACjC,GAAG,EAAE,MAAM;YACX,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "@spinajs/log-common";
2
+ export * from "./targets/index.js";
3
+ export * from "./log.js";
4
+ export * from "./decorators.js";
5
+ export * from "./bootstrap.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "@spinajs/log-common";
2
+ export * from "./targets/index.js";
3
+ export * from "./log.js";
4
+ export * from "./decorators.js";
5
+ export * from "./bootstrap.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
package/lib/log.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { Container, SyncService } from "@spinajs/di";
2
+ import { ILogOptions, ILogRule, ILogEntry, LogVariables, ILog, ILogTargetDesc } from "@spinajs/log-common";
3
+ /**
4
+ * Default log implementation interface. Taken from bunyan. Feel free to implement own.
5
+ */
6
+ export declare class Log extends SyncService implements ILog {
7
+ Name: string;
8
+ protected Parent?: Log;
9
+ static Loggers: Map<string, Log>;
10
+ static InternalLoggers: Map<string, Log>;
11
+ Timers: Map<string, Date>;
12
+ Targets: ILogTargetDesc[];
13
+ static clearLoggers(): void;
14
+ protected static AttachedToExitEvents: boolean;
15
+ protected Options: ILogOptions;
16
+ protected Rules: ILogRule[];
17
+ protected Variables: Record<string, any>;
18
+ protected Container: Container;
19
+ constructor(Name: string, variables?: Record<string, unknown>, Parent?: Log);
20
+ addVariable(name: string, value: unknown): void;
21
+ timeStart(name: string): void;
22
+ timeEnd(name: string): number;
23
+ resolve(): void;
24
+ trace(message: string, ...args: any[]): void;
25
+ trace(err: Error, message: string, ...args: any[]): void;
26
+ debug(message: string, ...args: any[]): void;
27
+ debug(err: Error, message: string, ...args: any[]): void;
28
+ info(message: string, ...args: any[]): void;
29
+ info(err: Error, message: string, ...args: any[]): void;
30
+ warn(message: string, ...args: any[]): void;
31
+ warn(err: Error, message: string, ...args: any[]): void;
32
+ error(message: string, ...args: any[]): void;
33
+ error(err: Error, message: string, ...args: any[]): void;
34
+ fatal(message: string, ...args: any[]): void;
35
+ fatal(err: Error, message: string, ...args: any[]): void;
36
+ security(message: string, ...args: any[]): void;
37
+ security(err: Error, message: string, ...args: any[]): void;
38
+ success(message: string, ...args: any[]): void;
39
+ success(err: Error, message: string, ...args: any[]): void;
40
+ write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>;
41
+ child(name: string, variables?: LogVariables): Log;
42
+ protected resolveLogTargets(): void;
43
+ protected matchRulesToLogger(): void;
44
+ }
45
+ //# sourceMappingURL=log.d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Q,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAK3D,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAC9C,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAK1D,KAAK,CAAC,KAAK,EAAE,SAAS;IActB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,YAAY,GAAG,GAAG;IAWzD,SAAS,CAAC,iBAAiB;IAoB3B,SAAS,CAAC,kBAAkB;CAQ7B"}
package/lib/log.js ADDED
@@ -0,0 +1,195 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var Log_1;
11
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
12
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
13
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
14
+ import { Configuration } from "@spinajs/configuration";
15
+ import { Autoinject, Container, DI, NewInstance, SyncService } from "@spinajs/di";
16
+ import { LogLevel, StrToLogLevel, createLogMessageObject } from "@spinajs/log-common";
17
+ import GlobToRegExp from "glob-to-regexp";
18
+ import { InvalidOperation, InvalidOption } from "../../exceptions/lib/index.js";
19
+ import { InternalLoggerProxy } from "@spinajs/internal-logger";
20
+ function wrapWrite(level) {
21
+ return (err, message, ...args) => {
22
+ if (err instanceof Error) {
23
+ return this.write(createLogMessageObject(err, message, level, this.Name, this.Variables, ...args));
24
+ }
25
+ else {
26
+ if (message) {
27
+ return this.write(createLogMessageObject(err, null, level, this.Name, this.Variables, ...[message, ...args]));
28
+ }
29
+ else {
30
+ return this.write(createLogMessageObject(err, null, level, this.Name, this.Variables, ...args));
31
+ }
32
+ }
33
+ };
34
+ }
35
+ /**
36
+ * Default log implementation interface. Taken from bunyan. Feel free to implement own.
37
+ */
38
+ let Log = Log_1 = class Log extends SyncService {
39
+ static { this.Loggers = new Map(); }
40
+ static { this.InternalLoggers = new Map(); }
41
+ static clearLoggers() {
42
+ Log_1.Loggers.clear();
43
+ }
44
+ static { this.AttachedToExitEvents = false; }
45
+ constructor(Name, variables, Parent) {
46
+ super();
47
+ this.Name = Name;
48
+ this.Parent = Parent;
49
+ this.Timers = new Map();
50
+ this.Variables = {};
51
+ this.Variables = variables ?? {};
52
+ }
53
+ addVariable(name, value) {
54
+ this.Variables[`${name}`] = value;
55
+ }
56
+ timeStart(name) {
57
+ if (this.Timers.has(name)) {
58
+ return;
59
+ }
60
+ this.Timers.set(name, new Date());
61
+ }
62
+ timeEnd(name) {
63
+ if (this.Timers.has(name)) {
64
+ const cTime = new Date();
65
+ const diff = cTime.getTime() - this.Timers.get(name).getTime();
66
+ this.Timers.delete(name);
67
+ return diff;
68
+ }
69
+ return 0;
70
+ }
71
+ resolve() {
72
+ const config = this.Container.get(Configuration);
73
+ if (!config) {
74
+ throw new Error(`Configuration module is not avaible. Please resolve configuration module before any logging can occur`);
75
+ }
76
+ this.Options = config.get("logger", {
77
+ targets: [
78
+ {
79
+ name: "Console",
80
+ type: "ConsoleTarget",
81
+ },
82
+ ],
83
+ rules: [{ name: "*", level: "trace", target: "Console" }],
84
+ });
85
+ this.matchRulesToLogger();
86
+ this.resolveLogTargets();
87
+ super.resolve();
88
+ Log_1.Loggers.set(this.Name, this);
89
+ }
90
+ trace(err, message, ...args) {
91
+ wrapWrite.apply(this, [LogLevel.Trace])(err, message, ...args);
92
+ }
93
+ debug(err, message, ...args) {
94
+ wrapWrite.apply(this, [LogLevel.Debug])(err, message, ...args);
95
+ }
96
+ info(err, message, ...args) {
97
+ wrapWrite.apply(this, [LogLevel.Info])(err, message, ...args);
98
+ }
99
+ warn(err, message, ...args) {
100
+ wrapWrite.apply(this, [LogLevel.Warn])(err, message, ...args);
101
+ }
102
+ error(err, message, ...args) {
103
+ wrapWrite.apply(this, [LogLevel.Error])(err, message, ...args);
104
+ }
105
+ fatal(err, message, ...args) {
106
+ wrapWrite.apply(this, [LogLevel.Fatal])(err, message, ...args);
107
+ }
108
+ security(err, message, ...args) {
109
+ wrapWrite.apply(this, [LogLevel.Security])(err, message, ...args);
110
+ }
111
+ success(err, message, ...args) {
112
+ wrapWrite.apply(this, [LogLevel.Success])(err, message, ...args);
113
+ }
114
+ write(entry) {
115
+ if (entry.Variables.logger === this.Name) {
116
+ return Promise.allSettled(this.Targets.filter((t) => entry.Level >= StrToLogLevel[t.rule.level]).map((t) => {
117
+ if (!t.instance) {
118
+ throw new InvalidOperation(`Target for rule ${t.rule.name} not exists`);
119
+ }
120
+ return t.instance.write(entry);
121
+ }));
122
+ }
123
+ }
124
+ child(name, variables) {
125
+ return DI.resolve(Log_1, [
126
+ `${this.Name}.${name}`,
127
+ {
128
+ ...this.Variables,
129
+ ...variables,
130
+ },
131
+ this,
132
+ ]);
133
+ }
134
+ resolveLogTargets() {
135
+ this.Targets = this.Rules.map((r) => {
136
+ const found = this.Options.targets.filter((t) => {
137
+ return Array.isArray(r.target) ? r.target.includes(t.name) : r.target === t.name;
138
+ });
139
+ if (!found) {
140
+ throw new InvalidOption(`No target matching rule ${r.name}`);
141
+ }
142
+ return found.map((f) => {
143
+ return {
144
+ instance: DI.resolve(f.type, [f]),
145
+ options: f,
146
+ rule: r,
147
+ };
148
+ });
149
+ }).reduce((prev, curr) => prev.concat(...curr), []);
150
+ }
151
+ matchRulesToLogger() {
152
+ this.Rules = this.Options.rules.filter((r) => {
153
+ const g = GlobToRegExp(r.name);
154
+ // BUG: g.test throws vscode err ?
155
+ return g.test(this.Name);
156
+ });
157
+ }
158
+ };
159
+ __decorate([
160
+ Autoinject(),
161
+ __metadata("design:type", Container)
162
+ ], Log.prototype, "Container", void 0);
163
+ Log = Log_1 = __decorate([
164
+ NewInstance(),
165
+ __metadata("design:paramtypes", [String, Object, Log])
166
+ ], Log);
167
+ export { Log };
168
+ const logFactoryFunction = (container, logName) => {
169
+ if (Log.Loggers.has(logName)) {
170
+ return Log.Loggers.get(logName);
171
+ }
172
+ if (!DI.has(Configuration)) {
173
+ if (Log.InternalLoggers.has(logName)) {
174
+ return Log.InternalLoggers.get(logName);
175
+ }
176
+ const internalLogger = container.resolve(InternalLoggerProxy, [logName]);
177
+ Log.InternalLoggers.set(logName, this);
178
+ return internalLogger;
179
+ }
180
+ return container.resolve("__logImplementation__", [logName]);
181
+ };
182
+ // register as string identifier to allow for
183
+ // resolving logs without referencing class
184
+ // to avoid circular dependencies in some @spinajs packages
185
+ // it should not be used in production code
186
+ DI.register(logFactoryFunction).as("__log__");
187
+ // register log factory function as Log class
188
+ // this way we can create or return already created
189
+ // log objects
190
+ DI.register(logFactoryFunction).as(Log);
191
+ // register Log class as string literal
192
+ // so we can resolve Log class
193
+ // it should not be used in production code
194
+ DI.register(Log).as("__logImplementation__");
195
+ //# sourceMappingURL=log.js.map
package/lib/log.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,EA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AO,SAAS,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/D,CAAC,CAAC;AAEF,6CAA6C;AAC7C,2CAA2C;AAC3C,2DAA2D;AAC3D,2CAA2C;AAC3C,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AAE9C,6CAA6C;AAC7C,mDAAmD;AACnD,cAAc;AACd,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;AAExC,uCAAuC;AACvC,8BAA8B;AAC9B,2CAA2C;AAC3C,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC"}
@@ -0,0 +1,88 @@
1
+ declare const CONFIGURATION_SCHEMA: {
2
+ $id: string;
3
+ $configurationModule: string;
4
+ description: string;
5
+ type: string;
6
+ properties: {
7
+ targets: {
8
+ description: string;
9
+ type: string;
10
+ minItems: number;
11
+ uniqueItems: boolean;
12
+ items: {
13
+ type: string;
14
+ properties: {
15
+ layout: {
16
+ type: string;
17
+ };
18
+ name: {
19
+ type: string;
20
+ };
21
+ type: {
22
+ type: string;
23
+ };
24
+ enabled: {
25
+ type: string;
26
+ };
27
+ path: {
28
+ type: string;
29
+ };
30
+ archivePath: {
31
+ type: string;
32
+ };
33
+ maxSize: {
34
+ type: string;
35
+ minimum: number;
36
+ };
37
+ compress: {
38
+ type: string;
39
+ };
40
+ rotate: {
41
+ type: string;
42
+ };
43
+ maxArchiveFiles: {
44
+ type: string;
45
+ minimum: number;
46
+ };
47
+ bufferSize: {
48
+ type: string;
49
+ minimum: number;
50
+ };
51
+ };
52
+ required: string[];
53
+ };
54
+ };
55
+ rules: {
56
+ description: string;
57
+ type: string;
58
+ minItems: number;
59
+ uniqueItems: boolean;
60
+ items: {
61
+ type: string;
62
+ properties: {
63
+ name: {
64
+ type: string;
65
+ };
66
+ level: {
67
+ type: string;
68
+ enum: string[];
69
+ };
70
+ target: {
71
+ oneOf: ({
72
+ type: string;
73
+ items?: undefined;
74
+ } | {
75
+ type: string;
76
+ items: {
77
+ type: string;
78
+ };
79
+ })[];
80
+ };
81
+ };
82
+ required: string[];
83
+ };
84
+ };
85
+ };
86
+ };
87
+ export default CONFIGURATION_SCHEMA;
88
+ //# sourceMappingURL=log.configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.configuration.d.ts","sourceRoot":"","sources":["../../src/schemas/log.configuration.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFzB,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,90 @@
1
+ const CONFIGURATION_SCHEMA = {
2
+ $id: "spinajs/log.configuration.schema.json",
3
+ $configurationModule: "logger",
4
+ description: "Logger configuration option validation",
5
+ type: "object",
6
+ properties: {
7
+ targets: {
8
+ description: "Log target, where log messages should be written to, and their options",
9
+ type: "array",
10
+ minItems: 1,
11
+ uniqueItems: true,
12
+ items: {
13
+ type: "object",
14
+ properties: {
15
+ layout: {
16
+ type: "string",
17
+ },
18
+ name: {
19
+ type: "string",
20
+ },
21
+ type: {
22
+ type: "string",
23
+ },
24
+ enabled: {
25
+ type: "boolean",
26
+ },
27
+ path: {
28
+ type: "string",
29
+ },
30
+ archivePath: {
31
+ type: "string",
32
+ },
33
+ maxSize: {
34
+ type: "integer",
35
+ minimum: 10000,
36
+ },
37
+ compress: {
38
+ type: "boolean",
39
+ },
40
+ rotate: {
41
+ type: "string",
42
+ },
43
+ maxArchiveFiles: {
44
+ type: "integer",
45
+ minimum: 1,
46
+ },
47
+ bufferSize: {
48
+ type: "integer",
49
+ minimum: 1000,
50
+ },
51
+ },
52
+ required: ["name", "type"],
53
+ },
54
+ },
55
+ rules: {
56
+ description: "Log rules, what log should be write where",
57
+ type: "array",
58
+ minItems: 1,
59
+ uniqueItems: true,
60
+ items: {
61
+ type: "object",
62
+ properties: {
63
+ name: {
64
+ type: "string",
65
+ },
66
+ level: {
67
+ type: "string",
68
+ enum: ["trace", "debug", "warn", "info", "error", "fatal", "security", "success"],
69
+ },
70
+ target: {
71
+ oneOf: [
72
+ {
73
+ type: "string",
74
+ },
75
+ {
76
+ type: "array",
77
+ items: {
78
+ type: "string",
79
+ },
80
+ },
81
+ ],
82
+ },
83
+ },
84
+ required: ["name", "level", "target"],
85
+ },
86
+ },
87
+ },
88
+ };
89
+ export default CONFIGURATION_SCHEMA;
90
+ //# sourceMappingURL=log.configuration.js.map
@@ -0,0 +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,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,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { ICommonTargetOptions, LogTarget } from "@spinajs/log-common";
2
+ /**
3
+ * Empty writer, usefull for tests or when we dont want to get any messages
4
+ */
5
+ export declare class BlackHoleTarget extends LogTarget<ICommonTargetOptions> {
6
+ write(): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=BlackHoleTarget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlackHoleTarget.d.ts","sourceRoot":"","sources":["../../src/targets/BlackHoleTarget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAItE;;GAEG;AACH,qBAEa,eAAgB,SAAQ,SAAS,CAAC,oBAAoB,CAAC;IACrD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
@@ -0,0 +1,22 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { LogTarget } from "@spinajs/log-common";
8
+ import { Injectable, Singleton } from "@spinajs/di";
9
+ /**
10
+ * Empty writer, usefull for tests or when we dont want to get any messages
11
+ */
12
+ let BlackHoleTarget = class BlackHoleTarget extends LogTarget {
13
+ async write() {
14
+ return;
15
+ }
16
+ };
17
+ BlackHoleTarget = __decorate([
18
+ Singleton(),
19
+ Injectable("BlackHoleTarget")
20
+ ], BlackHoleTarget);
21
+ export { BlackHoleTarget };
22
+ //# sourceMappingURL=BlackHoleTarget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlackHoleTarget.js","sourceRoot":"","sources":["../../src/targets/BlackHoleTarget.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAwB,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGpD;;GAEG;AAGI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,SAA+B;IAC3D,KAAK,CAAC,KAAK;QAChB,OAAO;IACT,CAAC;CACF,CAAA;AAJY,eAAe;IAF3B,SAAS,EAAE;IACX,UAAU,CAAC,iBAAiB,CAAC;GACjB,eAAe,CAI3B;SAJY,eAAe"}
@@ -0,0 +1,51 @@
1
+ import { IColoredConsoleTargetOptions, ILogEntry, LogTarget } from "@spinajs/log-common";
2
+ export declare const DEFAULT_THEME: {
3
+ security: string[];
4
+ fatal: string;
5
+ error: string;
6
+ warn: string;
7
+ success: string;
8
+ info: string;
9
+ debug: string;
10
+ trace: string;
11
+ };
12
+ export declare class ColoredConsoleTarget extends LogTarget<IColoredConsoleTargetOptions> {
13
+ protected theme: any[];
14
+ protected StdConsoleCallbackMap: {
15
+ 5: {
16
+ (...data: any[]): void;
17
+ (message?: any, ...optionalParams: any[]): void;
18
+ };
19
+ 6: {
20
+ (...data: any[]): void;
21
+ (message?: any, ...optionalParams: any[]): void;
22
+ };
23
+ 999: {
24
+ (...data: any[]): void;
25
+ (message?: any, ...optionalParams: any[]): void;
26
+ };
27
+ 2: {
28
+ (...data: any[]): void;
29
+ (message?: any, ...optionalParams: any[]): void;
30
+ };
31
+ 3: {
32
+ (...data: any[]): void;
33
+ (message?: any, ...optionalParams: any[]): void;
34
+ };
35
+ 0: {
36
+ (...data: any[]): void;
37
+ (message?: any, ...optionalParams: any[]): void;
38
+ };
39
+ 1: {
40
+ (...data: any[]): void;
41
+ (message?: any, ...optionalParams: any[]): void;
42
+ };
43
+ 4: {
44
+ (...data: any[]): void;
45
+ (message?: any, ...optionalParams: any[]): void;
46
+ };
47
+ };
48
+ resolve(): Promise<void>;
49
+ write(data: ILogEntry): Promise<void>;
50
+ }
51
+ //# sourceMappingURL=ColoredConsoleTarget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColoredConsoleTarget.d.ts","sourceRoot":"","sources":["../../src/targets/ColoredConsoleTarget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAMzF,eAAO,MAAM,aAAa;;;;;;;;;CASzB,CAAC;AAEF,qBAEa,oBAAqB,SAAQ,SAAS,CAAC,4BAA4B,CAAC;IAC/E,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,CAAM;IAE5B,SAAS,CAAC,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAY7B;IAEW,OAAO;IAaP,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAanD"}
@@ -0,0 +1,65 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { LogTarget } from "@spinajs/log-common";
8
+ import { Injectable, Singleton } from "@spinajs/di";
9
+ import { LogLevel } from "./../index.js";
10
+ import chalk from "chalk";
11
+ import { format } from "@spinajs/configuration";
12
+ export const DEFAULT_THEME = {
13
+ security: ["red", "bgBrightWhite"],
14
+ fatal: "red",
15
+ error: "brightRed",
16
+ warn: "yellow",
17
+ success: "green",
18
+ info: "white",
19
+ debug: "gray",
20
+ trace: "gray",
21
+ };
22
+ let ColoredConsoleTarget = class ColoredConsoleTarget extends LogTarget {
23
+ constructor() {
24
+ super(...arguments);
25
+ this.theme = [];
26
+ this.StdConsoleCallbackMap = {
27
+ [LogLevel.Error]: console.error,
28
+ [LogLevel.Fatal]: console.error,
29
+ [LogLevel.Security]: console.error,
30
+ [LogLevel.Info]: console.log,
31
+ [LogLevel.Success]: console.log,
32
+ [LogLevel.Trace]: console.debug,
33
+ [LogLevel.Debug]: console.debug,
34
+ [LogLevel.Warn]: console.warn,
35
+ };
36
+ }
37
+ async resolve() {
38
+ this.theme[LogLevel.Trace] = chalk.gray;
39
+ this.theme[LogLevel.Debug] = chalk.gray;
40
+ this.theme[LogLevel.Info] = chalk.white;
41
+ this.theme[LogLevel.Success] = chalk.white.bgGreen;
42
+ this.theme[LogLevel.Warn] = chalk.yellow;
43
+ this.theme[LogLevel.Error] = chalk.red;
44
+ this.theme[LogLevel.Fatal] = chalk.white.bgRed;
45
+ this.theme[LogLevel.Security] = chalk.yellow.bgRed;
46
+ super.resolve();
47
+ }
48
+ async write(data) {
49
+ if (!this.Options.enabled) {
50
+ return;
51
+ }
52
+ this.StdConsoleCallbackMap[data.Level](
53
+ /**
54
+ * we are safe to call, disable eslint
55
+ */
56
+ /* eslint-disable */
57
+ this.theme[data.Level](format(data.Variables, this.Options.layout)));
58
+ }
59
+ };
60
+ ColoredConsoleTarget = __decorate([
61
+ Singleton(),
62
+ Injectable("ConsoleTarget")
63
+ ], ColoredConsoleTarget);
64
+ export { ColoredConsoleTarget };
65
+ //# sourceMappingURL=ColoredConsoleTarget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ColoredConsoleTarget.js","sourceRoot":"","sources":["../../src/targets/ColoredConsoleTarget.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAA2C,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC;IAClC,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE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AAM,CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;QAEnD,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,IAAe;QAChC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACzB,OAAO;SACR;QAED,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC;QACpC;;WAEG;QACH,oBAAoB;QACnB,IAAI,CAAC,KAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAC7E,CAAC;IACJ,CAAC;CACF,CAAA;AA3CY,oBAAoB;IAFhC,SAAS,EAAE;IACX,UAAU,CAAC,eAAe,CAAC;GACf,oBAAoB,CA2ChC;SA3CY,oBAAoB"}
@@ -0,0 +1,30 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import { IInstanceCheck } from "@spinajs/di";
4
+ import { IFileTargetOptions, ILog, ILogEntry, LogTarget } from "@spinajs/log-common";
5
+ import * as fs from "fs";
6
+ import "@spinajs/configuration-common";
7
+ declare enum FileTargetStatus {
8
+ WRITTING = 0,
9
+ PENDING = 1,
10
+ IDLE = 2
11
+ }
12
+ export declare class FileTarget extends LogTarget<IFileTargetOptions> implements IInstanceCheck {
13
+ protected Log: ILog;
14
+ LogDirPath: string;
15
+ ArchiveDirPath: string;
16
+ protected WriteStream: fs.WriteStream;
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
+ write(data: ILogEntry): Promise<void>;
27
+ protected archive(): void;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=FileTarget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileTarget.d.ts","sourceRoot":"","sources":["../../src/targets/FileTarget.ts"],"names":[],"mappings":";;AAGA,OAAO,EAAE,cAAc,EAAgC,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAQzB,OAAO,+BAA+B,CAAC;AAEvC,aAAK,gBAAgB;IACnB,QAAQ,IAAA;IACR,OAAO,IAAA;IACP,IAAI,IAAA;CACL;AAID,qBAEa,UAAW,SAAQ,SAAS,CAAC,kBAAkB,CAAE,YAAW,cAAc;IAErF,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC;IAEb,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IAE9B,SAAS,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC;IACtC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;IAEhC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC;IACrC,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC;IAEnC,SAAS,CAAC,MAAM,EAAE,gBAAgB,CAAyB;IAC3D,SAAS,CAAC,aAAa,EAAE,gBAAgB,CAAyB;IAElE,iBAAiB,CAAC,eAAe,EAAE,kBAAkB,GAAG,OAAO;IAIxD,OAAO;IA4Dd,SAAS,CAAC,KAAK;IA0BF,OAAO;IAWP,KAAK,CAAC,IAAI,EAAE,SAAS;IAyBlC,SAAS,CAAC,OAAO;CA4FlB"}
@@ -0,0 +1,224 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ /* eslint-disable security/detect-object-injection */
11
+ import { EOL } from "os";
12
+ /* eslint security/detect-non-literal-fs-filename:0 -- Safe as no value holds user input */
13
+ import { Injectable, PerInstanceCheck } from "@spinajs/di";
14
+ import { LogTarget } from "@spinajs/log-common";
15
+ import * as fs from "fs";
16
+ import * as path from "path";
17
+ import { InvalidOption } from "../../../exceptions/lib/index.js";
18
+ import * as glob from "glob";
19
+ import * as zlib from "zlib";
20
+ import { format } from "@spinajs/configuration";
21
+ import { pipeline } from "stream";
22
+ import { Logger } from "./../decorators.js";
23
+ import "@spinajs/configuration-common";
24
+ var FileTargetStatus;
25
+ (function (FileTargetStatus) {
26
+ FileTargetStatus[FileTargetStatus["WRITTING"] = 0] = "WRITTING";
27
+ FileTargetStatus[FileTargetStatus["PENDING"] = 1] = "PENDING";
28
+ FileTargetStatus[FileTargetStatus["IDLE"] = 2] = "IDLE";
29
+ })(FileTargetStatus || (FileTargetStatus = {}));
30
+ // we mark per instance check becouse we can have multiple file targes
31
+ // for different files/paths/logs but we dont want to create every time writer for same.
32
+ let FileTarget = class FileTarget extends LogTarget {
33
+ constructor() {
34
+ super(...arguments);
35
+ this.Buffer = [];
36
+ this.Status = FileTargetStatus.IDLE;
37
+ this.ArchiveStatus = FileTargetStatus.IDLE;
38
+ }
39
+ __checkInstance__(creationOptions) {
40
+ return this.Options.name === creationOptions.name;
41
+ }
42
+ resolve() {
43
+ this.Options.options = Object.assign({
44
+ compress: true,
45
+ maxSize: 1024 * 1024,
46
+ maxArchiveFiles: 5,
47
+ archiveInterval: 3 * 60,
48
+ }, this.Options.options);
49
+ this.LogDirPath = path.dirname(path.resolve(format(null, this.Options.options.path)));
50
+ this.ArchiveDirPath = this.Options.options.archivePath ? path.resolve(format(null, this.Options.options.archivePath)) : this.LogDirPath;
51
+ if (!this.LogDirPath) {
52
+ throw new InvalidOption("Missing LogDirPath log option");
53
+ }
54
+ if (!fs.existsSync(this.LogDirPath)) {
55
+ fs.mkdirSync(this.LogDirPath);
56
+ }
57
+ if (this.ArchiveDirPath) {
58
+ if (!fs.existsSync(this.ArchiveDirPath)) {
59
+ fs.mkdirSync(this.ArchiveDirPath);
60
+ }
61
+ }
62
+ // flush all buffered messages at least once per second
63
+ // we do this, becouse buffer can not be filled
64
+ // and we could wait unknown amount of time before messages are written to file
65
+ this.FlushTimer = setInterval(() => {
66
+ // do not flush, if we already writting to file
67
+ if (this.Status !== FileTargetStatus.IDLE && this.ArchiveStatus !== FileTargetStatus.IDLE) {
68
+ return;
69
+ }
70
+ setImmediate(() => {
71
+ this.flush();
72
+ });
73
+ }, 1000);
74
+ // every 3 minutes try to archive log files
75
+ this.ArchiveTimer = setInterval(() => {
76
+ // do not archive if we already doing it
77
+ if (this.Status !== FileTargetStatus.IDLE && this.ArchiveStatus !== FileTargetStatus.IDLE) {
78
+ return;
79
+ }
80
+ this.ArchiveStatus = FileTargetStatus.PENDING;
81
+ // at end of nodejs event loop
82
+ setImmediate(() => {
83
+ this.archive();
84
+ });
85
+ }, this.Options.options.archiveInterval * 1000);
86
+ super.resolve();
87
+ }
88
+ flush() {
89
+ if (this.Buffer.length === 0) {
90
+ this.Status = FileTargetStatus.IDLE;
91
+ return;
92
+ }
93
+ this.Status = FileTargetStatus.WRITTING;
94
+ // we calculate log path every time to allow for
95
+ // dynamic path creation eg. based on timestamp
96
+ const logFileName = format({ logger: this.Options.name }, path.basename(this.Options.options.path));
97
+ const logPath = path.join(this.LogDirPath, logFileName);
98
+ fs.appendFile(logPath, this.Buffer.join(EOL) + EOL, (err) => {
99
+ // log error message to others if applicable eg. console
100
+ if (err) {
101
+ this.Log.error(err, `Cannot write log messages to file target at path ${logPath}`);
102
+ }
103
+ this.Log.trace(`Wrote buffered messages to log file at path ${logPath}, buffer size: ${this.Options.options.maxBufferSize}`);
104
+ this.Buffer = [];
105
+ this.Status = FileTargetStatus.IDLE;
106
+ });
107
+ }
108
+ async dispose() {
109
+ // stop archiving
110
+ clearInterval(this.ArchiveTimer);
111
+ // stop flush timer
112
+ clearInterval(this.FlushTimer);
113
+ // write all messages from buffer
114
+ this.flush();
115
+ }
116
+ async write(data) {
117
+ if (!this.Options.enabled) {
118
+ return;
119
+ }
120
+ const lEntry = format(data.Variables, this.Options.layout);
121
+ this.Buffer.push(lEntry);
122
+ // if we already writting, skip buffer check & write to file
123
+ // wait until write is finished
124
+ if (this.Status !== FileTargetStatus.IDLE || this.ArchiveStatus !== FileTargetStatus.IDLE) {
125
+ return;
126
+ }
127
+ if (this.Buffer.length >= this.Options.options.maxBufferSize) {
128
+ this.Status = FileTargetStatus.PENDING;
129
+ // write at end of nodejs event loop all buffered messages at once
130
+ setImmediate(() => {
131
+ this.flush();
132
+ });
133
+ }
134
+ }
135
+ archive() {
136
+ const { ext } = path.parse(path.basename(this.Options.options.path));
137
+ const aFiles = glob
138
+ .sync(path.join(this.ArchiveDirPath, `archived_*{${ext},.gzip}`))
139
+ .map((f) => {
140
+ return {
141
+ name: f,
142
+ stat: fs.statSync(f),
143
+ };
144
+ })
145
+ .sort((a, b) => a.stat.mtime.getTime() - b.stat.mtime.getTime());
146
+ const lFiles = glob
147
+ .sync(path.join(this.LogDirPath, `*${ext}`))
148
+ .map((f) => {
149
+ return {
150
+ name: f,
151
+ stat: fs.statSync(f),
152
+ };
153
+ })
154
+ .sort((a, b) => a.stat.mtime.getTime() - b.stat.mtime.getTime());
155
+ // clear archived files above limit
156
+ if (aFiles.length > this.Options.options.maxArchiveFiles) {
157
+ for (let i = 0; i < aFiles.length - this.Options.options.maxArchiveFiles; i++) {
158
+ fs.unlink(aFiles[i].name, (err) => {
159
+ if (err) {
160
+ this.Log.error(err, `Cannot delete archived file at path ${aFiles[i - 1].name}`);
161
+ }
162
+ else {
163
+ this.Log.info(`Deleted archived file at path ${aFiles[i].name}`);
164
+ }
165
+ });
166
+ }
167
+ }
168
+ // now move log files that are above limited file size or old
169
+ const filesToArchive = lFiles.filter((x) => {
170
+ return x.stat.size > this.Options.options.maxSize || lFiles.indexOf(x) <= lFiles.length - 2;
171
+ });
172
+ if (filesToArchive.length === 0) {
173
+ this.ArchiveStatus = FileTargetStatus.IDLE;
174
+ }
175
+ for (let i = 0; i < filesToArchive.length; i++) {
176
+ const { name, ext } = path.parse(path.basename(lFiles[i].name));
177
+ // get number of files with same name, eg. during a day, multiple log files can be produced
178
+ const lArchiFiles = glob.sync(path.join(this.ArchiveDirPath, `archived_${name}*{${ext},.gzip}`).replace(/\\/g, '/'));
179
+ const archPath = path.join(this.ArchiveDirPath, `archived_${name}_${lArchiFiles.length + 1}${ext}`);
180
+ fs.rename(lFiles[i].name, archPath, (err) => {
181
+ if (err) {
182
+ this.Log.error(err, `Cannot move log file ${name} to archive at path ${archPath}`);
183
+ return;
184
+ }
185
+ if (this.Options.options.compress) {
186
+ this.Log.trace(`Compressing archive log at path ${archPath}`);
187
+ const zippedPath = path.join(this.ArchiveDirPath, `archived_${name}_${lArchiFiles.length + 1}${ext}.gzip`);
188
+ const zip = zlib.createGzip();
189
+ const read = fs.createReadStream(archPath);
190
+ const write = fs.createWriteStream(zippedPath);
191
+ pipeline(read, zip, write, (err) => {
192
+ if (err) {
193
+ this.Log.error(err, `Cannot compress archived file at path ${archPath}`);
194
+ fs.unlink(zippedPath, () => {
195
+ return;
196
+ });
197
+ return;
198
+ }
199
+ this.Log.info(`Succesyfully compressed archive log at path ${zippedPath}`);
200
+ fs.unlink(archPath, (err) => {
201
+ if (err) {
202
+ this.Log.error(err, `Cannot delete archived log after compression at path ${archPath}`);
203
+ }
204
+ });
205
+ this.ArchiveStatus = FileTargetStatus.IDLE;
206
+ });
207
+ }
208
+ else {
209
+ this.ArchiveStatus = FileTargetStatus.IDLE;
210
+ }
211
+ });
212
+ }
213
+ }
214
+ };
215
+ __decorate([
216
+ Logger("LogFileTarget"),
217
+ __metadata("design:type", Object)
218
+ ], FileTarget.prototype, "Log", void 0);
219
+ FileTarget = __decorate([
220
+ PerInstanceCheck(),
221
+ Injectable("FileTarget")
222
+ ], FileTarget);
223
+ export { FileTarget };
224
+ //# sourceMappingURL=FileTarget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileTarget.js","sourceRoot":"","sources":["../../src/targets/FileTarget.ts"],"names":[],"mappings":";;;;;;;;;AAAA,qDAAqD;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC;AACzB,2FAA2F;AAC3F,OAAO,EAAkB,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAuC,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAA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ACJ;qBAAM;oBACL,IAAI,CAAC,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC;iBAC5C;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AAzOC;IAAC,MAAM,CAAC,eAAe,CAAC;;uCACJ;AAFT,UAAU;IAFtB,gBAAgB,EAAE;IAClB,UAAU,CAAC,YAAY,CAAC;GACZ,UAAU,CA0OtB;SA1OY,UAAU"}
@@ -0,0 +1,4 @@
1
+ export * from "./BlackHoleTarget.js";
2
+ export * from "./ColoredConsoleTarget.js";
3
+ export * from "./FileTarget.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/targets/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./BlackHoleTarget.js";
2
+ export * from "./ColoredConsoleTarget.js";
3
+ export * from "./FileTarget.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/targets/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spinajs/log",
3
- "version": "2.0.51",
3
+ "version": "2.0.53",
4
4
  "description": "Log lib for all spinejs related libs",
5
5
  "exports": "./lib/index.js",
6
6
  "type": "module",
@@ -8,6 +8,9 @@
8
8
  "engines": {
9
9
  "node": ">=16.11"
10
10
  },
11
+ "files": [
12
+ "lib/**/*"
13
+ ],
11
14
  "scripts": {
12
15
  "build": "npm run clean && npm run compile",
13
16
  "compile": "tsc -b tsconfig.json",
@@ -30,11 +33,11 @@
30
33
  "homepage": "https://github.com/spinajs/log#readme",
31
34
  "dependencies": {
32
35
  "@colors/colors": "^1.5.0",
33
- "@spinajs/configuration": "^2.0.46",
34
- "@spinajs/di": "^2.0.46",
35
- "@spinajs/exceptions": "^2.0.39",
36
- "@spinajs/internal-logger": "^2.0.46",
37
- "@spinajs/log-common": "^2.0.46",
36
+ "@spinajs/configuration": "^2.0.53",
37
+ "@spinajs/di": "^2.0.53",
38
+ "@spinajs/exceptions": "^2.0.53",
39
+ "@spinajs/internal-logger": "^2.0.53",
40
+ "@spinajs/log-common": "^2.0.53",
38
41
  "ajv": "^8.12.0",
39
42
  "chalk": "5.2.0",
40
43
  "glob": "^8.1.0",
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules
2
- lib
package/.eslintrc.cjs DELETED
@@ -1,45 +0,0 @@
1
- /*
2
- 👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3
- https://github.com/typescript-eslint/tslint-to-eslint-config
4
-
5
- It represents the closest reasonable ESLint configuration to this
6
- project's original TSLint configuration.
7
-
8
- We recommend eventually switching this configuration to extend from
9
- the recommended rulesets in typescript-eslint.
10
- https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11
-
12
- Happy linting! 💖
13
- */
14
- module.exports = {
15
- root: true,
16
- env: {
17
- browser: true,
18
- es6: true,
19
- },
20
- ignorePatterns: ['.eslintrc.js'],
21
- extends: [
22
- 'plugin:security/recommended',
23
- 'plugin:import/errors',
24
- 'plugin:import/warnings',
25
- 'plugin:import/typescript',
26
- 'plugin:promise/recommended',
27
- 'plugin:@typescript-eslint/recommended',
28
- 'plugin:@typescript-eslint/recommended-requiring-type-checking',
29
- ],
30
- parser: '@typescript-eslint/parser',
31
- parserOptions: {
32
- project: 'tsconfig.json',
33
- sourceType: 'module',
34
- },
35
- plugins: ['promise', 'prettier', 'eslint-plugin-import', 'eslint-plugin-prefer-arrow', '@typescript-eslint', 'tsdoc', 'security'],
36
- rules: {
37
- 'tsdoc/syntax': 'warn',
38
- 'import/no-unresolved': 'off',
39
-
40
- "@typescript-eslint/require-await": "off",
41
- "security/detect-unsafe-regex" : "off",
42
- '@typescript-eslint/no-explicit-any': 'off',
43
- },
44
- };
45
-
package/.mocharc.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extensions": ["ts"],
3
- "spec": ["packages/configuration/test/*.test.ts"],
4
- "node-option": [
5
- "experimental-specifier-resolution=node",
6
- "loader=ts-node/esm"
7
- ]
8
- }
package/typedoc.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "mode": "modules",
3
- "out": "docs",
4
- "name": "spine",
5
- "theme": "default",
6
- "ignoreCompilerErrors": "true",
7
- "experimentalDecorators": "true",
8
- "emitDecoratorMetadata": "true",
9
- "target": "ES6",
10
- "moduleResolution": "node",
11
- "preserveConstEnums": "true",
12
- "stripInternal": "true",
13
- "suppressExcessPropertyErrors": "true",
14
- "suppressImplicitAnyIndexErrors": "true",
15
- "module": "commonjs"
16
- }