@seidor-cloud-produtos/orbit-backend-lib 2.0.47 → 2.0.48
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/dist/clean-arch/application/logger/index.d.ts +13 -5
- package/dist/clean-arch/application/logger/index.js +23 -7
- package/dist/clean-arch/infra/logger/logger-in-memory.d.ts +5 -7
- package/dist/clean-arch/infra/logger/logger-in-memory.js +14 -29
- package/dist/clean-arch/infra/logger/logger-orbit.d.ts +12 -8
- package/dist/clean-arch/infra/logger/logger-orbit.js +9 -19
- package/package.json +1 -1
- package/dist/clean-arch/infra/logger/lib-logger.d.ts +0 -7
- package/dist/clean-arch/infra/logger/lib-logger.js +0 -15
|
@@ -16,17 +16,25 @@ export interface LogProperties {
|
|
|
16
16
|
}
|
|
17
17
|
export interface LogPropertiesInput {
|
|
18
18
|
level: LOG_LEVEL;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
}
|
|
20
|
+
export interface LogParams {
|
|
21
|
+
actor: string;
|
|
22
|
+
type: string;
|
|
21
23
|
}
|
|
22
24
|
export interface LogOptions {
|
|
23
25
|
}
|
|
24
26
|
export default abstract class LoggerGateway {
|
|
25
27
|
protected cache: Cache;
|
|
26
|
-
|
|
28
|
+
protected params: LogParams;
|
|
29
|
+
protected options?: LogOptions | undefined;
|
|
30
|
+
constructor(cache: Cache, params: LogParams, options?: LogOptions | undefined);
|
|
27
31
|
private static cacheKey;
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
info(...input: any[]): Promise<void>;
|
|
33
|
+
warn(...input: any[]): Promise<void>;
|
|
34
|
+
error(...input: any[]): Promise<void>;
|
|
35
|
+
debug(...input: any[]): Promise<void>;
|
|
36
|
+
log(props: LogPropertiesInput, ...dataToLog: any[]): Promise<void>;
|
|
37
|
+
protected abstract register(props: LogProperties, ...dataToLog: any[]): Promise<void> | void;
|
|
30
38
|
private static buildAcceptLogLevelValues;
|
|
31
39
|
protected isToLog(props: LogProperties, ...dataToLog: any[]): Promise<boolean | undefined>;
|
|
32
40
|
protected buildProps(props?: LogPropertiesInput): LogProperties;
|
|
@@ -14,22 +14,38 @@ var CategoryEnum;
|
|
|
14
14
|
})(CategoryEnum || (exports.CategoryEnum = CategoryEnum = {}));
|
|
15
15
|
class LoggerGateway {
|
|
16
16
|
cache;
|
|
17
|
-
|
|
17
|
+
params;
|
|
18
|
+
options;
|
|
19
|
+
constructor(cache, params, options) {
|
|
18
20
|
this.cache = cache;
|
|
21
|
+
this.params = params;
|
|
22
|
+
this.options = options;
|
|
19
23
|
}
|
|
20
24
|
static cacheKey = 'LOG_LEVEL';
|
|
21
|
-
async
|
|
25
|
+
async info(...input) {
|
|
26
|
+
return await this.log({ level: types_1.LOG_LEVEL.info }, input);
|
|
27
|
+
}
|
|
28
|
+
async warn(...input) {
|
|
29
|
+
return await this.log({ level: types_1.LOG_LEVEL.warn }, input);
|
|
30
|
+
}
|
|
31
|
+
async error(...input) {
|
|
32
|
+
return await this.log({ level: types_1.LOG_LEVEL.error }, input);
|
|
33
|
+
}
|
|
34
|
+
async debug(...input) {
|
|
35
|
+
return await this.log({ level: types_1.LOG_LEVEL.error }, input);
|
|
36
|
+
}
|
|
37
|
+
async log(props, ...dataToLog) {
|
|
22
38
|
try {
|
|
23
39
|
const buildedProperties = this.buildProps(props);
|
|
24
40
|
const isToLog = await this.isToLog(buildedProperties, dataToLog);
|
|
25
41
|
if (!isToLog) {
|
|
26
42
|
return;
|
|
27
43
|
}
|
|
28
|
-
return await this.register(buildedProperties,
|
|
44
|
+
return await this.register(buildedProperties, dataToLog);
|
|
29
45
|
}
|
|
30
46
|
catch (e) {
|
|
31
47
|
console.error('Error in log', e);
|
|
32
|
-
console.log('Input', props,
|
|
48
|
+
console.log('Input', props, dataToLog);
|
|
33
49
|
}
|
|
34
50
|
}
|
|
35
51
|
static buildAcceptLogLevelValues(level) {
|
|
@@ -78,14 +94,14 @@ class LoggerGateway {
|
|
|
78
94
|
...props,
|
|
79
95
|
};
|
|
80
96
|
}
|
|
81
|
-
return
|
|
97
|
+
return defaultProps;
|
|
82
98
|
}
|
|
83
99
|
buildDefaultProps() {
|
|
84
100
|
return {
|
|
85
101
|
level: types_1.LOG_LEVEL.info,
|
|
86
102
|
dateTime: new Date(),
|
|
87
|
-
actor:
|
|
88
|
-
type:
|
|
103
|
+
actor: this.params.actor,
|
|
104
|
+
type: this.params.type,
|
|
89
105
|
};
|
|
90
106
|
}
|
|
91
107
|
async setLevel(level, filter, ttl) {
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import LoggerGateway, { LogOptions, LogPropertiesInput } from '../../application/logger';
|
|
1
|
+
import LoggerGateway, { LogOptions, LogParams, LogPropertiesInput } from '../../application/logger';
|
|
2
2
|
import { Cache } from '../../../clean-arch/application/cache/cache';
|
|
3
3
|
export interface LoggerInMemoryOptions extends LogOptions {
|
|
4
4
|
showProps?: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare class LoggerInMemory extends LoggerGateway {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
private error;
|
|
12
|
-
private warning;
|
|
7
|
+
protected options: LoggerInMemoryOptions;
|
|
8
|
+
constructor(cache: Cache, params: LogParams, options?: LoggerInMemoryOptions);
|
|
9
|
+
log(props: LogPropertiesInput, ...dataToLog: any[]): Promise<void>;
|
|
10
|
+
protected register(props: LogPropertiesInput, ...dataToLog: any[]): void;
|
|
13
11
|
}
|
|
@@ -5,42 +5,27 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const logger_1 = tslib_1.__importDefault(require("../../application/logger"));
|
|
6
6
|
const types_1 = require("../environment/types");
|
|
7
7
|
class LoggerInMemory extends logger_1.default {
|
|
8
|
-
constructor(cache) {
|
|
9
|
-
super(cache);
|
|
8
|
+
constructor(cache, params, options) {
|
|
9
|
+
super(cache, params, options);
|
|
10
10
|
}
|
|
11
|
-
async log(props,
|
|
12
|
-
return await super.log(props,
|
|
11
|
+
async log(props, ...dataToLog) {
|
|
12
|
+
return await super.log(props, dataToLog);
|
|
13
13
|
}
|
|
14
|
-
register(props,
|
|
14
|
+
register(props, ...dataToLog) {
|
|
15
|
+
const params = [...dataToLog];
|
|
16
|
+
if (this.options?.showProps) {
|
|
17
|
+
params.push(props);
|
|
18
|
+
}
|
|
15
19
|
switch (props?.level) {
|
|
16
20
|
case types_1.LOG_LEVEL.error:
|
|
17
|
-
return
|
|
21
|
+
return console.error(...params);
|
|
18
22
|
case types_1.LOG_LEVEL.warn:
|
|
19
|
-
return
|
|
23
|
+
return console.warn(...params);
|
|
24
|
+
case types_1.LOG_LEVEL.debug:
|
|
25
|
+
return console.debug(...params);
|
|
20
26
|
default:
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
info(props, options, ...dataToLog) {
|
|
25
|
-
const params = [...dataToLog];
|
|
26
|
-
if (options?.showProps) {
|
|
27
|
-
params.push(props);
|
|
28
|
-
}
|
|
29
|
-
console.info(...params);
|
|
30
|
-
}
|
|
31
|
-
error(props, options, ...dataToLog) {
|
|
32
|
-
const params = [...dataToLog];
|
|
33
|
-
if (options?.showProps) {
|
|
34
|
-
params.push(props);
|
|
35
|
-
}
|
|
36
|
-
console.error(...params);
|
|
37
|
-
}
|
|
38
|
-
warning(props, options, ...dataToLog) {
|
|
39
|
-
const params = [...dataToLog];
|
|
40
|
-
if (options?.showProps) {
|
|
41
|
-
params.push(props);
|
|
27
|
+
return console.info(...params);
|
|
42
28
|
}
|
|
43
|
-
console.warn(...params);
|
|
44
29
|
}
|
|
45
30
|
}
|
|
46
31
|
exports.LoggerInMemory = LoggerInMemory;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Queue from '../../application/queue/queue';
|
|
2
|
-
import LoggerGateway, { ActorEnum, CategoryEnum, LogOptions, LogProperties, LogPropertiesInput } from '../../application/logger';
|
|
2
|
+
import LoggerGateway, { ActorEnum, CategoryEnum, LogOptions, LogParams, LogProperties, LogPropertiesInput } from '../../application/logger';
|
|
3
3
|
import DomainEvent from '../../domain/events/domain-event';
|
|
4
4
|
import { Cache } from '../../../clean-arch/application/cache/cache';
|
|
5
5
|
export interface LoggerOrbitOptions extends LogOptions {
|
|
@@ -8,8 +8,6 @@ export interface LoggerOrbitOptions extends LogOptions {
|
|
|
8
8
|
}
|
|
9
9
|
export interface LogOrbitPropertiesInput extends LogPropertiesInput {
|
|
10
10
|
id?: string;
|
|
11
|
-
actorType?: ActorEnum;
|
|
12
|
-
category?: CategoryEnum;
|
|
13
11
|
tenantId?: string;
|
|
14
12
|
dateTime?: Date;
|
|
15
13
|
expirationHours?: number;
|
|
@@ -20,15 +18,20 @@ export interface LogOrbitPropertiesInput extends LogPropertiesInput {
|
|
|
20
18
|
}
|
|
21
19
|
export interface LogOrbitProperties extends LogProperties {
|
|
22
20
|
id?: string;
|
|
21
|
+
tenantId?: string;
|
|
23
22
|
actorType: ActorEnum;
|
|
24
23
|
category: CategoryEnum;
|
|
25
|
-
tenantId?: string;
|
|
26
24
|
expirationHours: number;
|
|
27
25
|
trace?: {
|
|
28
26
|
mainId?: string;
|
|
29
27
|
ids: string[];
|
|
30
28
|
};
|
|
31
29
|
}
|
|
30
|
+
export interface LogOrbitParams extends LogParams {
|
|
31
|
+
actorType: ActorEnum;
|
|
32
|
+
category: CategoryEnum;
|
|
33
|
+
expirationHours: number;
|
|
34
|
+
}
|
|
32
35
|
export type LogPayload = Omit<LogProperties, 'expirationHours'> & {
|
|
33
36
|
expirationDate: Date;
|
|
34
37
|
details: any;
|
|
@@ -41,11 +44,12 @@ export default class LogEvent implements DomainEvent {
|
|
|
41
44
|
}
|
|
42
45
|
export declare class LoggerOrbit extends LoggerGateway {
|
|
43
46
|
private queue;
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
protected options: LoggerOrbitOptions;
|
|
48
|
+
protected params: LogOrbitParams;
|
|
49
|
+
constructor(queue: Queue, cache: Cache, params: LogOrbitParams, options?: LoggerOrbitOptions);
|
|
50
|
+
log(props: LogOrbitPropertiesInput, ...dataToLog: any[]): Promise<void>;
|
|
46
51
|
protected isToLog(props: LogOrbitProperties, ...dataToLog: any[]): Promise<boolean | undefined>;
|
|
47
|
-
register(data: any, props: LogOrbitPropertiesInput
|
|
52
|
+
register(data: any, props: LogOrbitPropertiesInput): Promise<void>;
|
|
48
53
|
private buildPayload;
|
|
49
54
|
protected buildDefaultProps(): LogOrbitProperties;
|
|
50
|
-
protected buildProps(props: LogOrbitPropertiesInput): LogOrbitProperties;
|
|
51
55
|
}
|
|
@@ -15,27 +15,27 @@ class LogEvent {
|
|
|
15
15
|
exports.default = LogEvent;
|
|
16
16
|
class LoggerOrbit extends logger_1.default {
|
|
17
17
|
queue;
|
|
18
|
-
constructor(queue, cache) {
|
|
19
|
-
super(cache);
|
|
18
|
+
constructor(queue, cache, params, options) {
|
|
19
|
+
super(cache, params, options);
|
|
20
20
|
this.queue = queue;
|
|
21
21
|
}
|
|
22
|
-
async log(props,
|
|
23
|
-
return await super.log(props,
|
|
22
|
+
async log(props, ...dataToLog) {
|
|
23
|
+
return await super.log(props, dataToLog);
|
|
24
24
|
}
|
|
25
25
|
async isToLog(props, ...dataToLog) {
|
|
26
26
|
return ((await super.isToLog(props, dataToLog)) ||
|
|
27
27
|
props.category === logger_1.CategoryEnum.BUSINESS);
|
|
28
28
|
}
|
|
29
|
-
async register(data, props
|
|
29
|
+
async register(data, props) {
|
|
30
30
|
try {
|
|
31
31
|
const payload = this.buildPayload(data, props);
|
|
32
32
|
await this.queue.publish('logservice.common.direct', new LogEvent(payload));
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
|
-
if (options?.retryStrategy) {
|
|
36
|
-
await options.retryStrategy(data, props
|
|
35
|
+
if (this.options?.retryStrategy) {
|
|
36
|
+
await this.options.retryStrategy(data, props);
|
|
37
37
|
}
|
|
38
|
-
if (options?.throwOnError) {
|
|
38
|
+
if (this.options?.throwOnError) {
|
|
39
39
|
throw new log_error_1.default();
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -58,20 +58,10 @@ class LoggerOrbit extends logger_1.default {
|
|
|
58
58
|
const sevenDaysInHours = 168;
|
|
59
59
|
return {
|
|
60
60
|
...super.buildDefaultProps(),
|
|
61
|
-
category:
|
|
61
|
+
category: this.params.category,
|
|
62
62
|
actorType: logger_1.ActorEnum.SYSTEM,
|
|
63
63
|
expirationHours: sevenDaysInHours * 4,
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
buildProps(props) {
|
|
67
|
-
let buildedProps = this.buildDefaultProps();
|
|
68
|
-
if (props) {
|
|
69
|
-
buildedProps = {
|
|
70
|
-
...buildedProps,
|
|
71
|
-
...props,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return buildedProps;
|
|
75
|
-
}
|
|
76
66
|
}
|
|
77
67
|
exports.LoggerOrbit = LoggerOrbit;
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { LogProperties } from '../../application/logger';
|
|
2
|
-
import { LoggerInMemory } from './logger-in-memory';
|
|
3
|
-
declare class LibLogger extends LoggerInMemory {
|
|
4
|
-
protected buildDefaultProps(): LogProperties;
|
|
5
|
-
}
|
|
6
|
-
declare const libLogger: LibLogger;
|
|
7
|
-
export default libLogger;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const cache_in_memory_1 = tslib_1.__importDefault(require("../cache/cache-in-memory"));
|
|
5
|
-
const logger_in_memory_1 = require("./logger-in-memory");
|
|
6
|
-
class LibLogger extends logger_in_memory_1.LoggerInMemory {
|
|
7
|
-
buildDefaultProps() {
|
|
8
|
-
return {
|
|
9
|
-
...super.buildDefaultProps(),
|
|
10
|
-
actor: 'lib-seidor-common',
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const libLogger = new LibLogger(cache_in_memory_1.default);
|
|
15
|
-
exports.default = libLogger;
|