zeddy-logger 1.0.0 → 1.0.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/.prettierrc +14 -14
- package/LICENSE +24 -24
- package/README.md +114 -114
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/logger-base.d.ts +18 -18
- package/dist/cjs/logger-base.d.ts.map +1 -1
- package/dist/cjs/logger-base.js +34 -31
- package/dist/cjs/logger-base.js.map +1 -1
- package/dist/cjs/outputs/console-output.d.ts +17 -17
- package/dist/cjs/outputs/console-output.js +41 -41
- package/dist/cjs/outputs/file-output.d.ts +12 -12
- package/dist/cjs/outputs/file-output.js +69 -69
- package/dist/cjs/outputs/outputs.d.ts +3 -3
- package/dist/cjs/outputs/outputs.js +7 -7
- package/dist/cjs/standard-logger.d.ts +26 -26
- package/dist/cjs/standard-logger.js +28 -28
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -3
- package/dist/esm/logger-base.d.ts +18 -18
- package/dist/esm/logger-base.d.ts.map +1 -1
- package/dist/esm/logger-base.js +20 -17
- package/dist/esm/logger-base.js.map +1 -1
- package/dist/esm/outputs/console-output.d.ts +17 -17
- package/dist/esm/outputs/console-output.js +25 -25
- package/dist/esm/outputs/file-output.d.ts +12 -12
- package/dist/esm/outputs/file-output.js +33 -33
- package/dist/esm/outputs/outputs.d.ts +3 -3
- package/dist/esm/outputs/outputs.js +3 -3
- package/dist/esm/standard-logger.d.ts +26 -26
- package/dist/esm/standard-logger.js +24 -24
- package/examples/logger.ts +19 -19
- package/package.json +51 -51
- package/tsconfig.base.json +105 -105
- package/tsconfig.cjs.json +8 -8
- package/tsconfig.esm.json +8 -8
- package/zeddy-logger-1.0.1.tgz +0 -0
- package/logs.txt +0 -7
package/.prettierrc
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"printWidth": 120,
|
|
3
|
-
"tabWidth": 2,
|
|
4
|
-
"useTabs": false,
|
|
5
|
-
"semi": true,
|
|
6
|
-
"quoteProps": "as-needed",
|
|
7
|
-
"jsxSingleQuote": false,
|
|
8
|
-
"singleQuote": true,
|
|
9
|
-
"trailingComma": "all",
|
|
10
|
-
"bracketSpacing": false,
|
|
11
|
-
"arrowParens": "always",
|
|
12
|
-
"proseWrap": "preserve",
|
|
13
|
-
"endOfLine": "auto"
|
|
14
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"printWidth": 120,
|
|
3
|
+
"tabWidth": 2,
|
|
4
|
+
"useTabs": false,
|
|
5
|
+
"semi": true,
|
|
6
|
+
"quoteProps": "as-needed",
|
|
7
|
+
"jsxSingleQuote": false,
|
|
8
|
+
"singleQuote": true,
|
|
9
|
+
"trailingComma": "all",
|
|
10
|
+
"bracketSpacing": false,
|
|
11
|
+
"arrowParens": "always",
|
|
12
|
+
"proseWrap": "preserve",
|
|
13
|
+
"endOfLine": "auto"
|
|
14
|
+
}
|
package/LICENSE
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
This is free and unencumbered software released into the public domain.
|
|
2
|
-
|
|
3
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
-
distribute this software, either in source code form or as a compiled
|
|
5
|
-
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
-
means.
|
|
7
|
-
|
|
8
|
-
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
-
of this software dedicate any and all copyright interest in the
|
|
10
|
-
software to the public domain. We make this dedication for the benefit
|
|
11
|
-
of the public at large and to the detriment of our heirs and
|
|
12
|
-
successors. We intend this dedication to be an overt act of
|
|
13
|
-
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
-
software under copyright law.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
|
|
24
|
-
For more information, please refer to <https://unlicense.org>
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
package/README.md
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
# Zeddy Logger
|
|
2
|
-
Zeddy Logger is a simple zero-dependency logging library that integrates well with NestJS
|
|
3
|
-
and allows great flexibility.
|
|
4
|
-
|
|
5
|
-
This library closely follows suggestions written in my upcoming book 'Pragmatic Node.js development: Primer in NestJS'.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Note
|
|
9
|
-
As this is only a library each app should create their own version of logger, but for simple projects provided
|
|
10
|
-
```StandardLogger``` is good base class to extend.
|
|
11
|
-
|
|
12
|
-
### Basic Usage
|
|
13
|
-
Simple example is provided below but more advanced usage for NestJS is in example repo https://github.com/zveljkovic/zeddy-logger-example
|
|
14
|
-
```typescript
|
|
15
|
-
// logger.ts
|
|
16
|
-
export class Logger extends StandardLogger {
|
|
17
|
-
constructor(filename: string) {
|
|
18
|
-
super([
|
|
19
|
-
new ConsoleOutput({
|
|
20
|
-
tagToConsoleFunctionMap: [
|
|
21
|
-
{tagName: 'log-level', tagValue: 'info', consoleFunction: 'info'},
|
|
22
|
-
{tagName: 'log-level', tagValue: 'debug', consoleFunction: 'debug'},
|
|
23
|
-
],
|
|
24
|
-
}),
|
|
25
|
-
new FileOutput({
|
|
26
|
-
filename,
|
|
27
|
-
}),
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// some code file
|
|
33
|
-
const logger = new Logger('logs.txt');
|
|
34
|
-
logger.info('test message', {a: 1, b: 2});
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### NestJS Request Based Logger
|
|
38
|
-
If you want to log some additional information from NestJS http request (for example some headers),
|
|
39
|
-
recommended way is to enrich the request object in interceptor.
|
|
40
|
-
|
|
41
|
-
```typescript
|
|
42
|
-
// app-request.ts
|
|
43
|
-
import {Request} from "express";
|
|
44
|
-
|
|
45
|
-
export type AppRequest = Request & { randomNumberFromInterceptor: number };
|
|
46
|
-
```
|
|
47
|
-
```typescript
|
|
48
|
-
// request.interceptor.ts
|
|
49
|
-
import {
|
|
50
|
-
Injectable,
|
|
51
|
-
NestInterceptor,
|
|
52
|
-
ExecutionContext,
|
|
53
|
-
CallHandler,
|
|
54
|
-
} from '@nestjs/common';
|
|
55
|
-
import { Observable } from 'rxjs';
|
|
56
|
-
import { AppRequest } from './app-request';
|
|
57
|
-
|
|
58
|
-
@Injectable()
|
|
59
|
-
export class RequestInterceptor implements NestInterceptor {
|
|
60
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
|
61
|
-
const request = context.switchToHttp().getRequest<AppRequest>();
|
|
62
|
-
request.randomNumberFromInterceptor = Math.random() * 42;
|
|
63
|
-
return next.handle();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
With the above we can plug it in NestJS and each request will contain ```randomNumberFromInterceptor```
|
|
68
|
-
but that could also be any value available in request.
|
|
69
|
-
|
|
70
|
-
With that value in request now we can create request scoped logger that will add
|
|
71
|
-
that value to any logs made with it.
|
|
72
|
-
|
|
73
|
-
```typescript
|
|
74
|
-
// request-based-logger.ts
|
|
75
|
-
import { Inject, Injectable, Scope } from '@nestjs/common';
|
|
76
|
-
import { AppRequest } from './app-request';
|
|
77
|
-
import { REQUEST } from '@nestjs/core';
|
|
78
|
-
import { StandardLogger } from 'zeddy-logger';
|
|
79
|
-
import { ConsoleOutput, FileOutput } from 'zeddy-logger/outputs';
|
|
80
|
-
|
|
81
|
-
@Injectable({ scope: Scope.REQUEST })
|
|
82
|
-
export class RequestBasedLogger extends StandardLogger {
|
|
83
|
-
constructor(@Inject(REQUEST) private request: AppRequest) {
|
|
84
|
-
const outputs = [
|
|
85
|
-
new ConsoleOutput({
|
|
86
|
-
transform: async (logData) => {
|
|
87
|
-
return {
|
|
88
|
-
message: logData.message,
|
|
89
|
-
tags: logData.tags,
|
|
90
|
-
data: {
|
|
91
|
-
...logData.data,
|
|
92
|
-
randomNumberFromInterceptor: request.randomNumberFromInterceptor,
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
|
-
},
|
|
96
|
-
tagToConsoleFunctionMap: [
|
|
97
|
-
{ tagName: 'log-level', tagValue: 'info', consoleFunction: 'info' },
|
|
98
|
-
{ tagName: 'log-level', tagValue: 'debug', consoleFunction: 'debug' },
|
|
99
|
-
],
|
|
100
|
-
}),
|
|
101
|
-
new FileOutput({
|
|
102
|
-
filename: 'logs.txt',
|
|
103
|
-
}),
|
|
104
|
-
];
|
|
105
|
-
super(outputs);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
### Example project
|
|
112
|
-
Example project can be found on [https://github.com/zveljkovic/zeddy-logger-example](https://github.com/zveljkovic/zeddy-logger-example).
|
|
113
|
-
It features even more advanced usage that allows not to react to "level" of the
|
|
114
|
-
log message but also on "type". This is useful if you want to
|
|
1
|
+
# Zeddy Logger
|
|
2
|
+
Zeddy Logger is a simple zero-dependency logging library that integrates well with NestJS
|
|
3
|
+
and allows great flexibility.
|
|
4
|
+
|
|
5
|
+
This library closely follows suggestions written in my upcoming book 'Pragmatic Node.js development: Primer in NestJS'.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Note
|
|
9
|
+
As this is only a library each app should create their own version of logger, but for simple projects provided
|
|
10
|
+
```StandardLogger``` is good base class to extend.
|
|
11
|
+
|
|
12
|
+
### Basic Usage
|
|
13
|
+
Simple example is provided below but more advanced usage for NestJS is in example repo https://github.com/zveljkovic/zeddy-logger-example
|
|
14
|
+
```typescript
|
|
15
|
+
// logger.ts
|
|
16
|
+
export class Logger extends StandardLogger {
|
|
17
|
+
constructor(filename: string) {
|
|
18
|
+
super([
|
|
19
|
+
new ConsoleOutput({
|
|
20
|
+
tagToConsoleFunctionMap: [
|
|
21
|
+
{tagName: 'log-level', tagValue: 'info', consoleFunction: 'info'},
|
|
22
|
+
{tagName: 'log-level', tagValue: 'debug', consoleFunction: 'debug'},
|
|
23
|
+
],
|
|
24
|
+
}),
|
|
25
|
+
new FileOutput({
|
|
26
|
+
filename,
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// some code file
|
|
33
|
+
const logger = new Logger('logs.txt');
|
|
34
|
+
logger.info('test message', {a: 1, b: 2});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### NestJS Request Based Logger
|
|
38
|
+
If you want to log some additional information from NestJS http request (for example some headers),
|
|
39
|
+
recommended way is to enrich the request object in interceptor.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// app-request.ts
|
|
43
|
+
import {Request} from "express";
|
|
44
|
+
|
|
45
|
+
export type AppRequest = Request & { randomNumberFromInterceptor: number };
|
|
46
|
+
```
|
|
47
|
+
```typescript
|
|
48
|
+
// request.interceptor.ts
|
|
49
|
+
import {
|
|
50
|
+
Injectable,
|
|
51
|
+
NestInterceptor,
|
|
52
|
+
ExecutionContext,
|
|
53
|
+
CallHandler,
|
|
54
|
+
} from '@nestjs/common';
|
|
55
|
+
import { Observable } from 'rxjs';
|
|
56
|
+
import { AppRequest } from './app-request';
|
|
57
|
+
|
|
58
|
+
@Injectable()
|
|
59
|
+
export class RequestInterceptor implements NestInterceptor {
|
|
60
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
|
|
61
|
+
const request = context.switchToHttp().getRequest<AppRequest>();
|
|
62
|
+
request.randomNumberFromInterceptor = Math.random() * 42;
|
|
63
|
+
return next.handle();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
With the above we can plug it in NestJS and each request will contain ```randomNumberFromInterceptor```
|
|
68
|
+
but that could also be any value available in request.
|
|
69
|
+
|
|
70
|
+
With that value in request now we can create request scoped logger that will add
|
|
71
|
+
that value to any logs made with it.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// request-based-logger.ts
|
|
75
|
+
import { Inject, Injectable, Scope } from '@nestjs/common';
|
|
76
|
+
import { AppRequest } from './app-request';
|
|
77
|
+
import { REQUEST } from '@nestjs/core';
|
|
78
|
+
import { StandardLogger } from 'zeddy-logger';
|
|
79
|
+
import { ConsoleOutput, FileOutput } from 'zeddy-logger/outputs';
|
|
80
|
+
|
|
81
|
+
@Injectable({ scope: Scope.REQUEST })
|
|
82
|
+
export class RequestBasedLogger extends StandardLogger {
|
|
83
|
+
constructor(@Inject(REQUEST) private request: AppRequest) {
|
|
84
|
+
const outputs = [
|
|
85
|
+
new ConsoleOutput({
|
|
86
|
+
transform: async (logData) => {
|
|
87
|
+
return {
|
|
88
|
+
message: logData.message,
|
|
89
|
+
tags: logData.tags,
|
|
90
|
+
data: {
|
|
91
|
+
...logData.data,
|
|
92
|
+
randomNumberFromInterceptor: request.randomNumberFromInterceptor,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
tagToConsoleFunctionMap: [
|
|
97
|
+
{ tagName: 'log-level', tagValue: 'info', consoleFunction: 'info' },
|
|
98
|
+
{ tagName: 'log-level', tagValue: 'debug', consoleFunction: 'debug' },
|
|
99
|
+
],
|
|
100
|
+
}),
|
|
101
|
+
new FileOutput({
|
|
102
|
+
filename: 'logs.txt',
|
|
103
|
+
}),
|
|
104
|
+
];
|
|
105
|
+
super(outputs);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### Example project
|
|
112
|
+
Example project can be found on [https://github.com/zveljkovic/zeddy-logger-example](https://github.com/zveljkovic/zeddy-logger-example).
|
|
113
|
+
It features even more advanced usage that allows not to react to "level" of the
|
|
114
|
+
log message but also on "type". This is useful if you want to
|
|
115
115
|
treat logs about outbound http requests differently from textual logs.
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LoggerBase } from './logger-base';
|
|
2
|
-
import { StandardLogger } from './standard-logger';
|
|
3
|
-
export { LoggerBase, StandardLogger };
|
|
1
|
+
import { LoggerBase } from './logger-base';
|
|
2
|
+
import { StandardLogger } from './standard-logger';
|
|
3
|
+
export { LoggerBase, StandardLogger };
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StandardLogger = exports.LoggerBase = void 0;
|
|
4
|
-
const logger_base_1 = require("./logger-base");
|
|
5
|
-
Object.defineProperty(exports, "LoggerBase", { enumerable: true, get: function () { return logger_base_1.LoggerBase; } });
|
|
6
|
-
const standard_logger_1 = require("./standard-logger");
|
|
7
|
-
Object.defineProperty(exports, "StandardLogger", { enumerable: true, get: function () { return standard_logger_1.StandardLogger; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StandardLogger = exports.LoggerBase = void 0;
|
|
4
|
+
const logger_base_1 = require("./logger-base");
|
|
5
|
+
Object.defineProperty(exports, "LoggerBase", { enumerable: true, get: function () { return logger_base_1.LoggerBase; } });
|
|
6
|
+
const standard_logger_1 = require("./standard-logger");
|
|
7
|
+
Object.defineProperty(exports, "StandardLogger", { enumerable: true, get: function () { return standard_logger_1.StandardLogger; } });
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export declare type LogTag = {
|
|
2
|
-
name: string;
|
|
3
|
-
value: string;
|
|
4
|
-
};
|
|
5
|
-
export declare type LogData = {
|
|
6
|
-
message: string;
|
|
7
|
-
data: any;
|
|
8
|
-
tags: LogTag[];
|
|
9
|
-
};
|
|
10
|
-
export declare type LogOutput = {
|
|
11
|
-
log: (logData: LogData) => Promise<void>;
|
|
12
|
-
transform?: (logData: LogData) => Promise<LogData | null>;
|
|
13
|
-
};
|
|
14
|
-
export declare class LoggerBase {
|
|
15
|
-
private logOutputs;
|
|
16
|
-
constructor(logOutputs: LogOutput[]);
|
|
17
|
-
log(logData: LogData): Promise<void>;
|
|
18
|
-
}
|
|
1
|
+
export declare type LogTag = {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
export declare type LogData = {
|
|
6
|
+
message: string;
|
|
7
|
+
data: any;
|
|
8
|
+
tags: LogTag[];
|
|
9
|
+
};
|
|
10
|
+
export declare type LogOutput = {
|
|
11
|
+
log: (logData: LogData) => Promise<void>;
|
|
12
|
+
transform?: (logData: LogData) => Promise<LogData | null>;
|
|
13
|
+
};
|
|
14
|
+
export declare class LoggerBase {
|
|
15
|
+
private logOutputs;
|
|
16
|
+
constructor(logOutputs: LogOutput[]);
|
|
17
|
+
log(logData: LogData): Promise<void>;
|
|
18
|
+
}
|
|
19
19
|
//# sourceMappingURL=logger-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-base.d.ts","sourceRoot":"","sources":["../../src/logger-base.ts"],"names":[],"mappings":"AAAA,oBAAY,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAC3D,CAAC;AAEF,qBAAa,UAAU;IACT,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,SAAS,EAAE;IAErC,GAAG,CAAC,OAAO,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"logger-base.d.ts","sourceRoot":"","sources":["../../src/logger-base.ts"],"names":[],"mappings":"AAAA,oBAAY,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,oBAAY,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACtB,GAAG,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAC3D,CAAC;AAEF,qBAAa,UAAU;IACT,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,SAAS,EAAE;IAErC,GAAG,CAAC,OAAO,EAAE,OAAO;CAc3B"}
|
package/dist/cjs/logger-base.js
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.LoggerBase = void 0;
|
|
13
|
-
class LoggerBase {
|
|
14
|
-
constructor(logOutputs) {
|
|
15
|
-
this.logOutputs = logOutputs;
|
|
16
|
-
}
|
|
17
|
-
log(logData) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
for (const logOutput of this.logOutputs) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LoggerBase = void 0;
|
|
13
|
+
class LoggerBase {
|
|
14
|
+
constructor(logOutputs) {
|
|
15
|
+
this.logOutputs = logOutputs;
|
|
16
|
+
}
|
|
17
|
+
log(logData) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
for (const logOutput of this.logOutputs) {
|
|
20
|
+
if (!logOutput.transform) {
|
|
21
|
+
// no transform function, just log
|
|
22
|
+
yield logOutput.log(logData);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
// There is a transformation function
|
|
26
|
+
// This might return null to prevent sending
|
|
27
|
+
const transformedLogData = yield logOutput.transform(logData);
|
|
28
|
+
if (transformedLogData)
|
|
29
|
+
yield logOutput.log(transformedLogData);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.LoggerBase = LoggerBase;
|
|
32
35
|
//# sourceMappingURL=logger-base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-base.js","sourceRoot":"","sources":["../../src/logger-base.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgBA,MAAa,UAAU;IACrB,YAAoB,UAAuB;QAAvB,eAAU,GAAV,UAAU,CAAa;IAAG,CAAC;IAEzC,GAAG,CAAC,OAAgB;;YACxB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;gBACvC,IAAI,
|
|
1
|
+
{"version":3,"file":"logger-base.js","sourceRoot":"","sources":["../../src/logger-base.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgBA,MAAa,UAAU;IACrB,YAAoB,UAAuB;QAAvB,eAAU,GAAV,UAAU,CAAa;IAAG,CAAC;IAEzC,GAAG,CAAC,OAAgB;;YACxB,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;gBACvC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE;oBACxB,kCAAkC;oBAClC,MAAM,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;oBAC7B,SAAS;iBACV;gBACD,qCAAqC;gBACrC,4CAA4C;gBAC5C,MAAM,kBAAkB,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC9D,IAAI,kBAAkB;oBACpB,MAAM,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;aAC3C;QACH,CAAC;KAAA;CACF;AAjBD,gCAiBC"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { LogData, LogOutput, LogTag } from '../logger-base';
|
|
2
|
-
export declare type ConsoleLogFunctions = 'info' | 'error' | 'debug' | 'log';
|
|
3
|
-
export declare type ConsoleFunctionMap = {
|
|
4
|
-
tagName: LogTag['name'];
|
|
5
|
-
tagValue: LogTag['value'];
|
|
6
|
-
consoleFunction: ConsoleLogFunctions;
|
|
7
|
-
};
|
|
8
|
-
export interface ConsoleOutputOptions {
|
|
9
|
-
transform?: (logData: LogData) => Promise<LogData>;
|
|
10
|
-
tagToConsoleFunctionMap?: ConsoleFunctionMap[];
|
|
11
|
-
}
|
|
12
|
-
export declare class ConsoleOutput implements LogOutput {
|
|
13
|
-
private opts;
|
|
14
|
-
constructor(opts: ConsoleOutputOptions);
|
|
15
|
-
log(logData: LogData): Promise<void>;
|
|
16
|
-
transform(logData: LogData): Promise<LogData>;
|
|
17
|
-
}
|
|
1
|
+
import { LogData, LogOutput, LogTag } from '../logger-base';
|
|
2
|
+
export declare type ConsoleLogFunctions = 'info' | 'error' | 'debug' | 'log';
|
|
3
|
+
export declare type ConsoleFunctionMap = {
|
|
4
|
+
tagName: LogTag['name'];
|
|
5
|
+
tagValue: LogTag['value'];
|
|
6
|
+
consoleFunction: ConsoleLogFunctions;
|
|
7
|
+
};
|
|
8
|
+
export interface ConsoleOutputOptions {
|
|
9
|
+
transform?: (logData: LogData) => Promise<LogData>;
|
|
10
|
+
tagToConsoleFunctionMap?: ConsoleFunctionMap[];
|
|
11
|
+
}
|
|
12
|
+
export declare class ConsoleOutput implements LogOutput {
|
|
13
|
+
private opts;
|
|
14
|
+
constructor(opts: ConsoleOutputOptions);
|
|
15
|
+
log(logData: LogData): Promise<void>;
|
|
16
|
+
transform(logData: LogData): Promise<LogData>;
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=console-output.d.ts.map
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ConsoleOutput = void 0;
|
|
13
|
-
class ConsoleOutput {
|
|
14
|
-
constructor(opts) {
|
|
15
|
-
this.opts = opts;
|
|
16
|
-
}
|
|
17
|
-
log(logData) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
let logFunction = 'log';
|
|
20
|
-
if (this.opts.tagToConsoleFunctionMap) {
|
|
21
|
-
for (const tag of logData.tags) {
|
|
22
|
-
const consoleFunctionMap = this.opts.tagToConsoleFunctionMap.filter((x) => x.tagName === tag.name && x.tagValue === tag.value);
|
|
23
|
-
if (consoleFunctionMap.length > 0) {
|
|
24
|
-
logFunction = consoleFunctionMap[0].consoleFunction;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (logData.data)
|
|
29
|
-
return console[logFunction](logData.message, logData.data);
|
|
30
|
-
return console[logFunction](logData.message);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
transform(logData) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
if (this.opts.transform)
|
|
36
|
-
return this.opts.transform(logData);
|
|
37
|
-
return logData;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.ConsoleOutput = ConsoleOutput;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ConsoleOutput = void 0;
|
|
13
|
+
class ConsoleOutput {
|
|
14
|
+
constructor(opts) {
|
|
15
|
+
this.opts = opts;
|
|
16
|
+
}
|
|
17
|
+
log(logData) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
let logFunction = 'log';
|
|
20
|
+
if (this.opts.tagToConsoleFunctionMap) {
|
|
21
|
+
for (const tag of logData.tags) {
|
|
22
|
+
const consoleFunctionMap = this.opts.tagToConsoleFunctionMap.filter((x) => x.tagName === tag.name && x.tagValue === tag.value);
|
|
23
|
+
if (consoleFunctionMap.length > 0) {
|
|
24
|
+
logFunction = consoleFunctionMap[0].consoleFunction;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (logData.data)
|
|
29
|
+
return console[logFunction](logData.message, logData.data);
|
|
30
|
+
return console[logFunction](logData.message);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
transform(logData) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (this.opts.transform)
|
|
36
|
+
return this.opts.transform(logData);
|
|
37
|
+
return logData;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.ConsoleOutput = ConsoleOutput;
|
|
42
42
|
//# sourceMappingURL=console-output.js.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { LogData, LogOutput } from '../logger-base';
|
|
2
|
-
export interface FileOutputOptions {
|
|
3
|
-
transform?: (logData: LogData) => Promise<LogData>;
|
|
4
|
-
filename: string;
|
|
5
|
-
}
|
|
6
|
-
export declare class FileOutput implements LogOutput {
|
|
7
|
-
private opts;
|
|
8
|
-
private readonly _fd;
|
|
9
|
-
constructor(opts: FileOutputOptions);
|
|
10
|
-
log(logData: LogData): Promise<void>;
|
|
11
|
-
transform(logData: LogData): Promise<LogData>;
|
|
12
|
-
}
|
|
1
|
+
import { LogData, LogOutput } from '../logger-base';
|
|
2
|
+
export interface FileOutputOptions {
|
|
3
|
+
transform?: (logData: LogData) => Promise<LogData>;
|
|
4
|
+
filename: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class FileOutput implements LogOutput {
|
|
7
|
+
private opts;
|
|
8
|
+
private readonly _fd;
|
|
9
|
+
constructor(opts: FileOutputOptions);
|
|
10
|
+
log(logData: LogData): Promise<void>;
|
|
11
|
+
transform(logData: LogData): Promise<LogData>;
|
|
12
|
+
}
|
|
13
13
|
//# sourceMappingURL=file-output.d.ts.map
|