@seidor-cloud-produtos/orbit-backend-lib 2.0.12 → 2.0.13
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 +5 -1
- package/dist/clean-arch/infra/logger/logger-in-memory.d.ts +2 -2
- package/dist/clean-arch/infra/logger/logger-in-memory.js +1 -1
- package/dist/clean-arch/infra/logger/logger-orbit.d.ts +2 -2
- package/dist/clean-arch/infra/logger/logger-orbit.js +8 -3
- package/package.json +1 -1
|
@@ -18,6 +18,10 @@ export type LogProperties = {
|
|
|
18
18
|
dateTime?: Date;
|
|
19
19
|
expirationHours?: number;
|
|
20
20
|
};
|
|
21
|
+
export interface LogOptions {
|
|
22
|
+
throwOnError?: boolean;
|
|
23
|
+
retryStrategy?: (data: any, props?: LogProperties, options?: LogOptions) => Promise<void>;
|
|
24
|
+
}
|
|
21
25
|
export default abstract class LoggerGateway {
|
|
22
|
-
abstract log(data: any, props?: LogProperties): Promise<void>;
|
|
26
|
+
abstract log(data: any, props?: LogProperties, options?: LogOptions): Promise<void>;
|
|
23
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import LoggerGateway, { LogProperties } from '../../application/logger';
|
|
1
|
+
import LoggerGateway, { LogOptions, LogProperties } from '../../application/logger';
|
|
2
2
|
export declare class LoggerInMemory extends LoggerGateway {
|
|
3
|
-
log(payload: any, props?: Partial<LogProperties
|
|
3
|
+
log(payload: any, props?: Partial<LogProperties>, options?: LogOptions): Promise<void>;
|
|
4
4
|
private info;
|
|
5
5
|
private error;
|
|
6
6
|
private warning;
|
|
@@ -6,7 +6,7 @@ const env_1 = require("../../infra/environment/env");
|
|
|
6
6
|
const logger_1 = tslib_1.__importDefault(require("../../application/logger"));
|
|
7
7
|
const types_1 = require("../environment/types");
|
|
8
8
|
class LoggerInMemory extends logger_1.default {
|
|
9
|
-
async log(payload, props) {
|
|
9
|
+
async log(payload, props, options) {
|
|
10
10
|
switch (props?.level) {
|
|
11
11
|
case types_1.LOG_LEVEL.error:
|
|
12
12
|
return this.error(payload, props);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Queue from '../../application/queue/queue';
|
|
2
|
-
import LoggerGateway, { LogProperties } from '../../application/logger';
|
|
2
|
+
import LoggerGateway, { LogOptions, LogProperties } from '../../application/logger';
|
|
3
3
|
import DomainEvent from '../../domain/events/domain-event';
|
|
4
4
|
export type LogPayload = Omit<LogProperties, 'expirationHours'> & {
|
|
5
5
|
expirationDate: Date;
|
|
@@ -14,7 +14,7 @@ export default class LogEvent implements DomainEvent {
|
|
|
14
14
|
export declare class LoggerOrbit extends LoggerGateway {
|
|
15
15
|
private queue;
|
|
16
16
|
constructor(queue: Queue);
|
|
17
|
-
log(data: any, props?: LogProperties): Promise<void>;
|
|
17
|
+
log(data: any, props?: LogProperties, options?: LogOptions): Promise<void>;
|
|
18
18
|
private buildPayload;
|
|
19
19
|
private buildProps;
|
|
20
20
|
protected buildDefaultProps(): LogProperties;
|
|
@@ -21,17 +21,22 @@ class LoggerOrbit extends logger_1.default {
|
|
|
21
21
|
super();
|
|
22
22
|
this.queue = queue;
|
|
23
23
|
}
|
|
24
|
-
async log(data, props) {
|
|
24
|
+
async log(data, props, options) {
|
|
25
25
|
const payload = this.buildPayload(data, props);
|
|
26
26
|
try {
|
|
27
27
|
await this.queue.publish('logservice.common.direct', new LogEvent(payload));
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
|
-
|
|
30
|
+
logger_in_memory_1.default.log({
|
|
31
31
|
message: 'SEND LOG ERROR: ',
|
|
32
32
|
error,
|
|
33
33
|
});
|
|
34
|
-
|
|
34
|
+
if (options?.retryStrategy) {
|
|
35
|
+
await options.retryStrategy(data, props, options);
|
|
36
|
+
}
|
|
37
|
+
if (options?.throwOnError) {
|
|
38
|
+
throw new log_error_1.default();
|
|
39
|
+
}
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
buildPayload(data, props) {
|