@spinajs/log 1.0.8 → 1.1.1
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/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 +71 -0
- package/lib/log.js +235 -0
- package/lib/log.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 +41 -0
- package/lib/targets/ColoredConsoleTarget.js +46 -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 +2383 -0
|
@@ -0,0 +1,6 @@
|
|
|
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?: {}): (target: any, key: string) => any;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const di_1 = require("@spinajs/di");
|
|
5
|
+
const log_1 = require("./log");
|
|
6
|
+
/**
|
|
7
|
+
* Creates ( if not exists ) new logger instance with given name and optional variables
|
|
8
|
+
* @param name name of logger
|
|
9
|
+
* @param variables optional log variables
|
|
10
|
+
*/
|
|
11
|
+
function Logger(name, variables) {
|
|
12
|
+
return (target, key) => {
|
|
13
|
+
let logger;
|
|
14
|
+
// property getter
|
|
15
|
+
const getter = () => {
|
|
16
|
+
if (!logger) {
|
|
17
|
+
const allLoggers = di_1.DI.get(Array.ofType(log_1.Log));
|
|
18
|
+
const found = allLoggers.find(l => l.Name);
|
|
19
|
+
if (found) {
|
|
20
|
+
logger = found;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
logger = di_1.DI.resolve(log_1.Log, [name, variables]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return logger;
|
|
27
|
+
};
|
|
28
|
+
// Create new property with getter and setter
|
|
29
|
+
Object.defineProperty(target, key, {
|
|
30
|
+
get: getter,
|
|
31
|
+
enumerable: false,
|
|
32
|
+
configurable: false
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.Logger = Logger;
|
|
37
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;AACjC,+BAA4B;AAG5B;;;;GAIG;AACH,SAAgB,MAAM,CAAC,IAAY,EAAE,SAAc;IAC/C,OAAO,CAAC,MAAW,EAAE,GAAW,EAAO,EAAE;QACrC,IAAI,MAAW,CAAC;QAEhB,kBAAkB;QAClB,MAAM,MAAM,GAAG,GAAG,EAAE;YAChB,IAAI,CAAC,MAAM,EAAE;gBAET,MAAM,UAAU,GAAG,OAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,SAAG,CAAC,CAAC,CAAC;gBAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAE3C,IAAI,KAAK,EAAE;oBACP,MAAM,GAAG,KAAK,CAAC;iBAClB;qBAAM;oBACH,MAAM,GAAG,OAAE,CAAC,OAAO,CAAC,SAAG,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;iBAC/C;aACJ;YACD,OAAO,MAAM,CAAC;QAClB,CAAC,CAAC;QAEF,6CAA6C;QAC7C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YAC/B,GAAG,EAAE,MAAM;YACX,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;SACtB,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC;AA3BD,wBA2BC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,227 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* -----------------------------------------------------------------------------------
|
|
7
|
-
* IMPORTANT: log subsystem is havily based on bunyan. It uses bunyan by default, all options & functions are based on
|
|
8
|
-
* bunyan lib. However you can implement custom log module and inject it to framework simply by implementing
|
|
9
|
-
* `LogModule` that returns custom implementation of `Log` interface. Then override default DI registered class at app bootstrap.
|
|
10
|
-
*
|
|
11
|
-
* If you simply want to add more places where log goes eg. database, simply add custom log stream to configuration file.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Creates child logger
|
|
15
|
-
*
|
|
16
|
-
* @param options - additional logger options
|
|
17
|
-
*/
|
|
18
|
-
export declare function Logger(options?: any): (target?: any, key?: string) => any;
|
|
19
|
-
/**
|
|
20
|
-
* Log stream that writes messages in console with proper colours for message types.
|
|
21
|
-
* * TRACE - gray
|
|
22
|
-
* * DEBUG - white
|
|
23
|
-
* * INFO - cyan
|
|
24
|
-
* * WARN - yellow
|
|
25
|
-
* * ERROR - red
|
|
26
|
-
* * FATAL - red on white background
|
|
27
|
-
*/
|
|
28
|
-
export declare class ConsoleLogStream extends Writable {
|
|
29
|
-
private TRACE;
|
|
30
|
-
private DEBUG;
|
|
31
|
-
private INFO;
|
|
32
|
-
private WARN;
|
|
33
|
-
private ERROR;
|
|
34
|
-
private FATAL;
|
|
35
|
-
write(chunk: any): boolean;
|
|
36
|
-
private _getNameFromType;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Default log implementation interface. Taken from bunyan. Feel free to implement own.
|
|
40
|
-
*/
|
|
41
|
-
export interface Log {
|
|
42
|
-
/**
|
|
43
|
-
* Returns a boolean: is the `trace` level enabled?
|
|
44
|
-
*
|
|
45
|
-
* This is equivalent to `log.isTraceEnabled()` or `log.isEnabledFor(TRACE)` in log4j.
|
|
46
|
-
*/
|
|
47
|
-
trace(): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Special case to log an `Error` instance to the record.
|
|
50
|
-
* This adds an `err` field with exception details
|
|
51
|
-
* (including the stack) and sets `msg` to the exception
|
|
52
|
-
* message or you can specify the `msg`.
|
|
53
|
-
*/
|
|
54
|
-
trace(error: Error, ...params: any[]): void;
|
|
55
|
-
/**
|
|
56
|
-
* The first field can optionally be a "fields" object, which
|
|
57
|
-
* is merged into the log record.
|
|
58
|
-
*
|
|
59
|
-
* To pass in an Error *and* other fields, use the `err`
|
|
60
|
-
* field name for the Error instance.
|
|
61
|
-
*/
|
|
62
|
-
trace(obj: Object, ...params: any[]): void;
|
|
63
|
-
/**
|
|
64
|
-
* Uses `util.format` for msg formatting.
|
|
65
|
-
*/
|
|
66
|
-
trace(format: any, ...params: any[]): void;
|
|
67
|
-
/**
|
|
68
|
-
* Returns a boolean: is the `debug` level enabled?
|
|
69
|
-
*
|
|
70
|
-
* This is equivalent to `log.isDebugEnabled()` or `log.isEnabledFor(DEBUG)` in log4j.
|
|
71
|
-
*/
|
|
72
|
-
debug(): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Special case to log an `Error` instance to the record.
|
|
75
|
-
* This adds an `err` field with exception details
|
|
76
|
-
* (including the stack) and sets `msg` to the exception
|
|
77
|
-
* message or you can specify the `msg`.
|
|
78
|
-
*/
|
|
79
|
-
debug(error: Error, ...params: any[]): void;
|
|
80
|
-
/**
|
|
81
|
-
* The first field can optionally be a "fields" object, which
|
|
82
|
-
* is merged into the log record.
|
|
83
|
-
*
|
|
84
|
-
* To pass in an Error *and* other fields, use the `err`
|
|
85
|
-
* field name for the Error instance.
|
|
86
|
-
*/
|
|
87
|
-
debug(obj: Object, ...params: any[]): void;
|
|
88
|
-
/**
|
|
89
|
-
* Uses `util.format` for msg formatting.
|
|
90
|
-
*/
|
|
91
|
-
debug(format: any, ...params: any[]): void;
|
|
92
|
-
/**
|
|
93
|
-
* Returns a boolean: is the `info` level enabled?
|
|
94
|
-
*
|
|
95
|
-
* This is equivalent to `log.isInfoEnabled()` or `log.isEnabledFor(INFO)` in log4j.
|
|
96
|
-
*/
|
|
97
|
-
info(): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Special case to log an `Error` instance to the record.
|
|
100
|
-
* This adds an `err` field with exception details
|
|
101
|
-
* (including the stack) and sets `msg` to the exception
|
|
102
|
-
* message or you can specify the `msg`.
|
|
103
|
-
*/
|
|
104
|
-
info(error: Error, ...params: any[]): void;
|
|
105
|
-
/**
|
|
106
|
-
* The first field can optionally be a "fields" object, which
|
|
107
|
-
* is merged into the log record.
|
|
108
|
-
*
|
|
109
|
-
* To pass in an Error *and* other fields, use the `err`
|
|
110
|
-
* field name for the Error instance.
|
|
111
|
-
*/
|
|
112
|
-
info(obj: Object, ...params: any[]): void;
|
|
113
|
-
/**
|
|
114
|
-
* Uses `util.format` for msg formatting.
|
|
115
|
-
*/
|
|
116
|
-
info(format: any, ...params: any[]): void;
|
|
117
|
-
/**
|
|
118
|
-
* Returns a boolean: is the `warn` level enabled?
|
|
119
|
-
*
|
|
120
|
-
* This is equivalent to `log.isWarnEnabled()` or `log.isEnabledFor(WARN)` in log4j.
|
|
121
|
-
*/
|
|
122
|
-
warn(): boolean;
|
|
123
|
-
/**
|
|
124
|
-
* Special case to log an `Error` instance to the record.
|
|
125
|
-
* This adds an `err` field with exception details
|
|
126
|
-
* (including the stack) and sets `msg` to the exception
|
|
127
|
-
* message or you can specify the `msg`.
|
|
128
|
-
*/
|
|
129
|
-
warn(error: Error, ...params: any[]): void;
|
|
130
|
-
/**
|
|
131
|
-
* The first field can optionally be a "fields" object, which
|
|
132
|
-
* is merged into the log record.
|
|
133
|
-
*
|
|
134
|
-
* To pass in an Error *and* other fields, use the `err`
|
|
135
|
-
* field name for the Error instance.
|
|
136
|
-
*/
|
|
137
|
-
warn(obj: Object, ...params: any[]): void;
|
|
138
|
-
/**
|
|
139
|
-
* Uses `util.format` for msg formatting.
|
|
140
|
-
*/
|
|
141
|
-
warn(format: any, ...params: any[]): void;
|
|
142
|
-
/**
|
|
143
|
-
* Returns a boolean: is the `error` level enabled?
|
|
144
|
-
*
|
|
145
|
-
* This is equivalent to `log.isErrorEnabled()` or `log.isEnabledFor(ERROR)` in log4j.
|
|
146
|
-
*/
|
|
147
|
-
error(): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* Special case to log an `Error` instance to the record.
|
|
150
|
-
* This adds an `err` field with exception details
|
|
151
|
-
* (including the stack) and sets `msg` to the exception
|
|
152
|
-
* message or you can specify the `msg`.
|
|
153
|
-
*/
|
|
154
|
-
error(error: Error, ...params: any[]): void;
|
|
155
|
-
/**
|
|
156
|
-
* The first field can optionally be a "fields" object, which
|
|
157
|
-
* is merged into the log record.
|
|
158
|
-
*
|
|
159
|
-
* To pass in an Error *and* other fields, use the `err`
|
|
160
|
-
* field name for the Error instance.
|
|
161
|
-
*/
|
|
162
|
-
error(obj: Object, ...params: any[]): void;
|
|
163
|
-
/**
|
|
164
|
-
* Uses `util.format` for msg formatting.
|
|
165
|
-
*/
|
|
166
|
-
error(format: any, ...params: any[]): void;
|
|
167
|
-
/**
|
|
168
|
-
* Returns a boolean: is the `fatal` level enabled?
|
|
169
|
-
*
|
|
170
|
-
* This is equivalent to `log.isFatalEnabled()` or `log.isEnabledFor(FATAL)` in log4j.
|
|
171
|
-
*/
|
|
172
|
-
fatal(): boolean;
|
|
173
|
-
/**
|
|
174
|
-
* Special case to log an `Error` instance to the record.
|
|
175
|
-
* This adds an `err` field with exception details
|
|
176
|
-
* (including the stack) and sets `msg` to the exception
|
|
177
|
-
* message or you can specify the `msg`.
|
|
178
|
-
*/
|
|
179
|
-
fatal(error: Error, ...params: any[]): void;
|
|
180
|
-
/**
|
|
181
|
-
* The first field can optionally be a "fields" object, which
|
|
182
|
-
* is merged into the log record.
|
|
183
|
-
*
|
|
184
|
-
* To pass in an Error *and* other fields, use the `err`
|
|
185
|
-
* field name for the Error instance.
|
|
186
|
-
*/
|
|
187
|
-
fatal(obj: Object, ...params: any[]): void;
|
|
188
|
-
/**
|
|
189
|
-
* Uses `util.format` for msg formatting.
|
|
190
|
-
*/
|
|
191
|
-
fatal(format: any, ...params: any[]): void;
|
|
192
|
-
child(options: Object, simple?: boolean): Log;
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Abstract class to implement for framework log module.
|
|
196
|
-
*/
|
|
197
|
-
export declare abstract class LogModule extends SyncModule {
|
|
198
|
-
abstract getLogger(options?: any[]): Log;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Default Log implementation that uses bunyan internally. Feel free to implement own
|
|
202
|
-
*/
|
|
203
|
-
export declare class SpinaJsDefaultLog extends LogModule {
|
|
204
|
-
/**
|
|
205
|
-
* Injected Configuration object
|
|
206
|
-
*/
|
|
207
|
-
cfg: Configuration;
|
|
208
|
-
/**
|
|
209
|
-
* root logger
|
|
210
|
-
* @access protected
|
|
211
|
-
*/
|
|
212
|
-
protected log: Log;
|
|
213
|
-
/**
|
|
214
|
-
* Name of module
|
|
215
|
-
* @access protected
|
|
216
|
-
*/
|
|
217
|
-
protected name: string;
|
|
218
|
-
/**
|
|
219
|
-
* Creates child logger
|
|
220
|
-
* @param options - additional logger options eg. fields.
|
|
221
|
-
*/
|
|
222
|
-
getLogger(options?: any[]): Log;
|
|
223
|
-
/**
|
|
224
|
-
* Initializes bunyan logger & hooks for process:uncaughtException to log fatal application events
|
|
225
|
-
*/
|
|
226
|
-
resolve(): void;
|
|
227
|
-
}
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./targets";
|
|
3
|
+
export * from "./variables";
|
|
4
|
+
export * from "./log";
|
|
5
|
+
export * from "./decorators";
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// tslint:disable: ban-types
|
|
3
|
-
// tslint:disable: interface-name
|
|
4
|
-
// tslint:disable: unified-signatures
|
|
5
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
3
|
if (k2 === undefined) k2 = k;
|
|
7
4
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
@@ -9,203 +6,13 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
9
6
|
if (k2 === undefined) k2 = k;
|
|
10
7
|
o[k2] = m[k];
|
|
11
8
|
}));
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
}) : function(o, v) {
|
|
15
|
-
o["default"] = v;
|
|
16
|
-
});
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
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;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
24
|
-
if (mod && mod.__esModule) return mod;
|
|
25
|
-
var result = {};
|
|
26
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
27
|
-
__setModuleDefault(result, mod);
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
31
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
32
|
-
};
|
|
33
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
34
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
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);
|
|
35
11
|
};
|
|
36
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const di_1 = require("@spinajs/di");
|
|
43
|
-
/**
|
|
44
|
-
* -----------------------------------------------------------------------------------
|
|
45
|
-
* IMPORTANT: log subsystem is havily based on bunyan. It uses bunyan by default, all options & functions are based on
|
|
46
|
-
* bunyan lib. However you can implement custom log module and inject it to framework simply by implementing
|
|
47
|
-
* `LogModule` that returns custom implementation of `Log` interface. Then override default DI registered class at app bootstrap.
|
|
48
|
-
*
|
|
49
|
-
* If you simply want to add more places where log goes eg. database, simply add custom log stream to configuration file.
|
|
50
|
-
*/
|
|
51
|
-
/**
|
|
52
|
-
* Creates child logger
|
|
53
|
-
*
|
|
54
|
-
* @param options - additional logger options
|
|
55
|
-
*/
|
|
56
|
-
function Logger(options) {
|
|
57
|
-
return (target, key) => {
|
|
58
|
-
let logger;
|
|
59
|
-
// property getter
|
|
60
|
-
const getter = () => {
|
|
61
|
-
if (!logger) {
|
|
62
|
-
logger = di_1.DI.get("LogModule").getLogger(options);
|
|
63
|
-
}
|
|
64
|
-
return logger;
|
|
65
|
-
};
|
|
66
|
-
// Create new property with getter and setter
|
|
67
|
-
Object.defineProperty(target, key, {
|
|
68
|
-
get: getter,
|
|
69
|
-
enumerable: false,
|
|
70
|
-
configurable: false
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
exports.Logger = Logger;
|
|
75
|
-
/**
|
|
76
|
-
* Log stream that writes messages in console with proper colours for message types.
|
|
77
|
-
* * TRACE - gray
|
|
78
|
-
* * DEBUG - white
|
|
79
|
-
* * INFO - cyan
|
|
80
|
-
* * WARN - yellow
|
|
81
|
-
* * ERROR - red
|
|
82
|
-
* * FATAL - red on white background
|
|
83
|
-
*/
|
|
84
|
-
class ConsoleLogStream extends stream_1.Writable {
|
|
85
|
-
constructor() {
|
|
86
|
-
super(...arguments);
|
|
87
|
-
this.TRACE = 10;
|
|
88
|
-
this.DEBUG = 20;
|
|
89
|
-
this.INFO = 30;
|
|
90
|
-
this.WARN = 40;
|
|
91
|
-
this.ERROR = 50;
|
|
92
|
-
this.FATAL = 60;
|
|
93
|
-
}
|
|
94
|
-
write(chunk) {
|
|
95
|
-
const type = this._getNameFromType(chunk.level);
|
|
96
|
-
const err = chunk.err
|
|
97
|
-
? `Exception: ${chunk.err.name}, ${chunk.err.message}, ${chunk.err.stack}`
|
|
98
|
-
: "";
|
|
99
|
-
const message = `${chunk.time.toISOString()} ${type} ${chunk.name}: ${chunk.msg} (module=${chunk.module}) ${err}`;
|
|
100
|
-
let c = null;
|
|
101
|
-
switch (chunk.level) {
|
|
102
|
-
case this.TRACE:
|
|
103
|
-
c = chalk_1.default.gray(message);
|
|
104
|
-
break;
|
|
105
|
-
case this.DEBUG:
|
|
106
|
-
c = chalk_1.default.white(message);
|
|
107
|
-
break;
|
|
108
|
-
case this.INFO:
|
|
109
|
-
c = chalk_1.default.cyan(message);
|
|
110
|
-
break;
|
|
111
|
-
case this.WARN:
|
|
112
|
-
c = chalk_1.default.yellow(message);
|
|
113
|
-
break;
|
|
114
|
-
case this.ERROR:
|
|
115
|
-
c = chalk_1.default.red(message);
|
|
116
|
-
break;
|
|
117
|
-
case this.FATAL:
|
|
118
|
-
c = chalk_1.default.bgRed.white(message);
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
console.log(c);
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
_getNameFromType(type) {
|
|
125
|
-
switch (type) {
|
|
126
|
-
case this.TRACE:
|
|
127
|
-
return "TRACE";
|
|
128
|
-
case this.DEBUG:
|
|
129
|
-
return "DEBUG";
|
|
130
|
-
case this.INFO:
|
|
131
|
-
return "INFO";
|
|
132
|
-
case this.WARN:
|
|
133
|
-
return "WARN";
|
|
134
|
-
case this.ERROR:
|
|
135
|
-
return "ERROR";
|
|
136
|
-
case this.FATAL:
|
|
137
|
-
return "FATAL";
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
exports.ConsoleLogStream = ConsoleLogStream;
|
|
142
|
-
/**
|
|
143
|
-
* Default logger options
|
|
144
|
-
* used as fallback if no config is provided
|
|
145
|
-
*/
|
|
146
|
-
const DEFAULT_OPTIONS = {
|
|
147
|
-
name: "spine-framework",
|
|
148
|
-
serializers: bunyan.stdSerializers,
|
|
149
|
-
/**
|
|
150
|
-
* streams to log to. See more on bunyan docs
|
|
151
|
-
*/
|
|
152
|
-
streams: [
|
|
153
|
-
{
|
|
154
|
-
type: "raw",
|
|
155
|
-
/**
|
|
156
|
-
* We use default console log stream with colors
|
|
157
|
-
*/
|
|
158
|
-
stream: new ConsoleLogStream(),
|
|
159
|
-
level: process.env.NODE_ENV === "development" ? "trace" : "info"
|
|
160
|
-
}
|
|
161
|
-
]
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Abstract class to implement for framework log module.
|
|
165
|
-
*/
|
|
166
|
-
class LogModule extends di_1.SyncModule {
|
|
167
|
-
}
|
|
168
|
-
exports.LogModule = LogModule;
|
|
169
|
-
/**
|
|
170
|
-
* Default Log implementation that uses bunyan internally. Feel free to implement own
|
|
171
|
-
*/
|
|
172
|
-
let SpinaJsDefaultLog = class SpinaJsDefaultLog extends LogModule {
|
|
173
|
-
constructor() {
|
|
174
|
-
super(...arguments);
|
|
175
|
-
/**
|
|
176
|
-
* Injected Configuration object
|
|
177
|
-
*/
|
|
178
|
-
this.cfg = null;
|
|
179
|
-
/**
|
|
180
|
-
* Name of module
|
|
181
|
-
* @access protected
|
|
182
|
-
*/
|
|
183
|
-
this.name = "Log";
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Creates child logger
|
|
187
|
-
* @param options - additional logger options eg. fields.
|
|
188
|
-
*/
|
|
189
|
-
getLogger(options) {
|
|
190
|
-
return this.log.child(options);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Initializes bunyan logger & hooks for process:uncaughtException to log fatal application events
|
|
194
|
-
*/
|
|
195
|
-
resolve() {
|
|
196
|
-
// get config
|
|
197
|
-
this.log = bunyan.createLogger(this.cfg.get(["log"], DEFAULT_OPTIONS));
|
|
198
|
-
process.on("uncaughtException", (err) => {
|
|
199
|
-
this.log.fatal(err);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
__decorate([
|
|
204
|
-
di_1.Autoinject(),
|
|
205
|
-
__metadata("design:type", configuration_1.Configuration)
|
|
206
|
-
], SpinaJsDefaultLog.prototype, "cfg", void 0);
|
|
207
|
-
SpinaJsDefaultLog = __decorate([
|
|
208
|
-
di_1.Injectable(LogModule)
|
|
209
|
-
], SpinaJsDefaultLog);
|
|
210
|
-
exports.SpinaJsDefaultLog = SpinaJsDefaultLog;
|
|
13
|
+
__exportStar(require("./types"), exports);
|
|
14
|
+
__exportStar(require("./targets"), exports);
|
|
15
|
+
__exportStar(require("./variables"), exports);
|
|
16
|
+
__exportStar(require("./log"), exports);
|
|
17
|
+
__exportStar(require("./decorators"), exports);
|
|
211
18
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B;AAC5B,wCAAsB;AACtB,+CAA6B"}
|
package/lib/log.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { IContainer, SyncModule } from "@spinajs/di";
|
|
2
|
+
import { LogTarget } from "./targets/LogTarget";
|
|
3
|
+
import { ICommonTargetOptions, LogLevel, ILogOptions, ILogRule, ILogTargetData, ITargetsOption } from "./types";
|
|
4
|
+
import { DataValidator } from "@spinajs/validation";
|
|
5
|
+
interface ILogTargetDesc {
|
|
6
|
+
instance: LogTarget<ICommonTargetOptions>;
|
|
7
|
+
options?: ITargetsOption;
|
|
8
|
+
rule: ILogRule;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Default log implementation interface. Taken from bunyan. Feel free to implement own.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Log extends SyncModule {
|
|
14
|
+
Name: string;
|
|
15
|
+
Variables?: any;
|
|
16
|
+
protected Parent?: Log;
|
|
17
|
+
/**
|
|
18
|
+
* STATIC METHODS FOR LOGGER, ALLOWS TO LOG TO ANY TARGET
|
|
19
|
+
* EVEN BEFORE LOG MODULE INITIALIZATION.
|
|
20
|
+
*
|
|
21
|
+
* Prevents from losing log message when initializing modules
|
|
22
|
+
*/
|
|
23
|
+
static Loggers: Map<string, Log>;
|
|
24
|
+
static trace(message: string, name: string, ...args: any[]): void;
|
|
25
|
+
static trace(err: Error, message: string, name: string, ...args: any[]): void;
|
|
26
|
+
static debug(message: string, name: string, ...args: any[]): void;
|
|
27
|
+
static debug(err: Error, message: string, name: string, ...args: any[]): void;
|
|
28
|
+
static info(message: string, name: string, ...args: any[]): void;
|
|
29
|
+
static info(err: Error, message: string, name: string, ...args: any[]): void;
|
|
30
|
+
static warn(message: string, name: string, ...args: any[]): void;
|
|
31
|
+
static warn(err: Error, message: string, name: string, ...args: any[]): void;
|
|
32
|
+
static error(message: string, name: string, ...args: any[]): void;
|
|
33
|
+
static error(err: Error, message: string, name: string, ...args: any[]): void;
|
|
34
|
+
static fatal(message: string, name: string, ...args: any[]): void;
|
|
35
|
+
static fatal(err: Error, message: string, name: string, ...args: any[]): void;
|
|
36
|
+
static security(message: string, name: string, ...args: any[]): void;
|
|
37
|
+
static security(err: Error, message: string, name: string, ...args: any[]): void;
|
|
38
|
+
static success(message: string, name: string, ...args: any[]): void;
|
|
39
|
+
static success(err: Error, message: string, name: string, ...args: any[]): void;
|
|
40
|
+
protected static LogBuffer: Map<string, ILogTargetData[]>;
|
|
41
|
+
protected static AttachedToExitEvents: boolean;
|
|
42
|
+
protected static write(err: Error | string, message: string | any[], level: LogLevel, name: string, ...args: any[]): void;
|
|
43
|
+
protected Options: ILogOptions;
|
|
44
|
+
protected Rules: ILogRule[];
|
|
45
|
+
protected Targets: ILogTargetDesc[];
|
|
46
|
+
protected Validator: DataValidator;
|
|
47
|
+
constructor(Name: string, Variables?: any, Parent?: Log);
|
|
48
|
+
resolve(_: IContainer): void;
|
|
49
|
+
trace(message: string, ...args: any[]): void;
|
|
50
|
+
trace(err: Error, message: string, ...args: any[]): void;
|
|
51
|
+
debug(message: string, ...args: any[]): void;
|
|
52
|
+
debug(err: Error, message: string, ...args: any[]): void;
|
|
53
|
+
info(message: string, ...args: any[]): void;
|
|
54
|
+
info(err: Error, message: string, ...args: any[]): void;
|
|
55
|
+
warn(message: string, ...args: any[]): void;
|
|
56
|
+
warn(err: Error, message: string, ...args: any[]): void;
|
|
57
|
+
error(message: string, ...args: any[]): void;
|
|
58
|
+
error(err: Error, message: string, ...args: any[]): void;
|
|
59
|
+
fatal(message: string, ...args: any[]): void;
|
|
60
|
+
fatal(err: Error, message: string, ...args: any[]): void;
|
|
61
|
+
security(message: string, ...args: any[]): void;
|
|
62
|
+
security(err: Error, message: string, ...args: any[]): void;
|
|
63
|
+
success(message: string, ...args: any[]): void;
|
|
64
|
+
success(err: Error, message: string, ...args: any[]): void;
|
|
65
|
+
child(name: string, variables?: {}): Log;
|
|
66
|
+
protected writeBufferedMessages(): void;
|
|
67
|
+
protected resolveLogTargets(): void;
|
|
68
|
+
protected matchRulesToLogger(): void;
|
|
69
|
+
protected write(err: Error | string, message: string | any[], level: LogLevel, ...args: any[]): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|