@punks/backend-core 0.0.49 → 0.0.50
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/cjs/index.js +18 -100
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/abstractions/logging.d.ts +6 -6
- package/dist/cjs/types/logging/concrete/consoleLogger.d.ts +9 -0
- package/dist/cjs/types/logging/concrete/datadogLogger.d.ts +19 -0
- package/dist/cjs/types/logging/concrete/index.d.ts +2 -0
- package/dist/cjs/types/logging/service.d.ts +14 -6
- package/dist/esm/index.js +18 -100
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/abstractions/logging.d.ts +6 -6
- package/dist/esm/types/logging/concrete/consoleLogger.d.ts +9 -0
- package/dist/esm/types/logging/concrete/datadogLogger.d.ts +19 -0
- package/dist/esm/types/logging/concrete/index.d.ts +2 -0
- package/dist/esm/types/logging/service.d.ts +14 -6
- package/dist/index.d.ts +18 -11
- package/package.json +5 -3
- package/dist/cjs/types/logging/concrete/defaultLogger.d.ts +0 -11
- package/dist/esm/types/logging/concrete/defaultLogger.d.ts +0 -11
|
@@ -10,12 +10,12 @@ export declare enum MetaSerializationType {
|
|
|
10
10
|
JSON = 1
|
|
11
11
|
}
|
|
12
12
|
export interface ILoggerProvider {
|
|
13
|
-
debug(message: string, meta?: any): void;
|
|
14
|
-
info(message: string, meta?: any): void;
|
|
15
|
-
warn(message: string, meta?: any): void;
|
|
16
|
-
error(message: string, meta?: any): void;
|
|
17
|
-
fatal(message: string, meta?: any): void;
|
|
18
|
-
exception(message: string, error: Error, meta?: any): void;
|
|
13
|
+
debug(loggerName: string, message: string, meta?: any): void;
|
|
14
|
+
info(loggerName: string, message: string, meta?: any): void;
|
|
15
|
+
warn(loggerName: string, message: string, meta?: any): void;
|
|
16
|
+
error(loggerName: string, message: string, meta?: any): void;
|
|
17
|
+
fatal(loggerName: string, message: string, meta?: any): void;
|
|
18
|
+
exception(loggerName: string, message: string, error: Error, meta?: any): void;
|
|
19
19
|
}
|
|
20
20
|
export interface ILogger {
|
|
21
21
|
debug(message: string, meta?: any): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ILoggerProvider } from "../../abstractions";
|
|
2
|
+
export declare class ConsoleLogger implements ILoggerProvider {
|
|
3
|
+
debug(loggerName: string, message: string, meta?: any): void;
|
|
4
|
+
info(loggerName: string, message: string, meta?: any): void;
|
|
5
|
+
warn(loggerName: string, message: string, meta?: any): void;
|
|
6
|
+
error(loggerName: string, message: string, meta?: any): void;
|
|
7
|
+
fatal(loggerName: string, message: string, meta?: any): void;
|
|
8
|
+
exception(loggerName: string, message: string, error: Error, meta?: any): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ILoggerProvider } from "../../abstractions";
|
|
2
|
+
export type DatadogLoggingSettings = {
|
|
3
|
+
service: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
appName: string;
|
|
6
|
+
roleName: string;
|
|
7
|
+
environmentName: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class DatadogLogger implements ILoggerProvider {
|
|
10
|
+
private readonly settings;
|
|
11
|
+
private readonly logger;
|
|
12
|
+
constructor(settings: DatadogLoggingSettings);
|
|
13
|
+
debug(loggerName: string, message: string, meta?: any): void;
|
|
14
|
+
info(loggerName: string, message: string, meta?: any): void;
|
|
15
|
+
warn(loggerName: string, message: string, meta?: any): void;
|
|
16
|
+
error(loggerName: string, message: string, meta?: any): void;
|
|
17
|
+
fatal(loggerName: string, message: string, meta?: any): void;
|
|
18
|
+
exception(loggerName: string, message: string, error: Error, meta?: any): void;
|
|
19
|
+
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import { ILogger, LogLevel, MetaSerializationType } from "../abstractions";
|
|
1
|
+
import { ILogger, ILoggerProvider, LogLevel, MetaSerializationType } from "../abstractions";
|
|
2
|
+
export type LoggerInstance = {
|
|
3
|
+
options: LoggerOptions;
|
|
4
|
+
provider: ILoggerProvider;
|
|
5
|
+
};
|
|
6
|
+
type LoggerOptions = {
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
level: LogLevel;
|
|
9
|
+
loggerName?: string;
|
|
10
|
+
serialization: MetaSerializationType;
|
|
11
|
+
};
|
|
2
12
|
export declare class Log {
|
|
3
|
-
private static readonly
|
|
4
|
-
static
|
|
5
|
-
static setLevel(level: LogLevel): void;
|
|
6
|
-
static enable(): void;
|
|
7
|
-
static disable(): void;
|
|
13
|
+
private static readonly container;
|
|
14
|
+
static configure(instance: LoggerInstance): void;
|
|
8
15
|
static getLogger(loggerName: string): ILogger;
|
|
9
16
|
}
|
|
17
|
+
export {};
|
package/dist/esm/index.js
CHANGED
|
@@ -28406,103 +28406,40 @@ const excelParse = (file, options) => {
|
|
|
28406
28406
|
.map((x) => aggregateRow(header, x, options));
|
|
28407
28407
|
};
|
|
28408
28408
|
|
|
28409
|
-
class
|
|
28410
|
-
constructor(loggerName) {
|
|
28409
|
+
class InternalLogger {
|
|
28410
|
+
constructor(loggerName, container) {
|
|
28411
28411
|
this.loggerName = loggerName;
|
|
28412
|
+
this.container = container;
|
|
28412
28413
|
}
|
|
28413
28414
|
debug(message, meta) {
|
|
28414
|
-
|
|
28415
|
-
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28416
|
-
}
|
|
28417
|
-
else {
|
|
28418
|
-
console.log(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28419
|
-
}
|
|
28415
|
+
this.getEnabledInstances(LogLevel.Debug).forEach((x) => x.provider.debug(this.loggerName, message, this.serializeMeta(x.options, meta)));
|
|
28420
28416
|
}
|
|
28421
28417
|
info(message, meta) {
|
|
28422
|
-
|
|
28423
|
-
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28424
|
-
}
|
|
28425
|
-
else {
|
|
28426
|
-
console.info(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28427
|
-
}
|
|
28418
|
+
this.getEnabledInstances(LogLevel.Info).forEach((x) => x.provider.info(this.loggerName, message, this.serializeMeta(x.options, meta)));
|
|
28428
28419
|
}
|
|
28429
28420
|
warn(message, meta) {
|
|
28430
|
-
|
|
28431
|
-
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28432
|
-
}
|
|
28433
|
-
else {
|
|
28434
|
-
console.warn(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28435
|
-
}
|
|
28421
|
+
this.getEnabledInstances(LogLevel.Warn).forEach((x) => x.provider.warn(this.loggerName, message, this.serializeMeta(x.options, meta)));
|
|
28436
28422
|
}
|
|
28437
28423
|
error(message, meta) {
|
|
28438
|
-
|
|
28439
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28440
|
-
}
|
|
28441
|
-
else {
|
|
28442
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28443
|
-
}
|
|
28424
|
+
this.getEnabledInstances(LogLevel.Error).forEach((x) => x.provider.error(this.loggerName, message, this.serializeMeta(x.options, meta)));
|
|
28444
28425
|
}
|
|
28445
28426
|
fatal(message, meta) {
|
|
28446
|
-
|
|
28447
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, meta);
|
|
28448
|
-
}
|
|
28449
|
-
else {
|
|
28450
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`);
|
|
28451
|
-
}
|
|
28427
|
+
this.getEnabledInstances(LogLevel.Fatal).forEach((x) => x.provider.fatal(this.loggerName, message, this.serializeMeta(x.options, meta)));
|
|
28452
28428
|
}
|
|
28453
28429
|
exception(message, error, meta) {
|
|
28454
|
-
|
|
28455
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error, meta);
|
|
28456
|
-
}
|
|
28457
|
-
else {
|
|
28458
|
-
console.error(`${this.loggerName ? `[${this.loggerName}] ` : ""}${message}`, error);
|
|
28459
|
-
}
|
|
28430
|
+
this.getEnabledInstances(LogLevel.Error).forEach((x) => x.provider.exception(this.loggerName, message, error, this.serializeMeta(x.options, meta)));
|
|
28460
28431
|
}
|
|
28461
|
-
|
|
28462
|
-
|
|
28463
|
-
class InternalLogger {
|
|
28464
|
-
constructor(options, provider) {
|
|
28465
|
-
this.options = options;
|
|
28466
|
-
this.provider = provider;
|
|
28432
|
+
getEnabledInstances(level) {
|
|
28433
|
+
return this.container.instances.filter((x) => x.options.enabled && x.options.level <= level);
|
|
28467
28434
|
}
|
|
28468
|
-
|
|
28469
|
-
if (this.options.enabled && this.options.level === LogLevel.Debug) {
|
|
28470
|
-
this.provider.debug(message, this.serializeMeta(meta));
|
|
28471
|
-
}
|
|
28472
|
-
}
|
|
28473
|
-
info(message, meta) {
|
|
28474
|
-
if (this.options.enabled && this.options.level <= LogLevel.Info) {
|
|
28475
|
-
this.provider.info(message, this.serializeMeta(meta));
|
|
28476
|
-
}
|
|
28477
|
-
}
|
|
28478
|
-
warn(message, meta) {
|
|
28479
|
-
if (this.options.enabled && this.options.level <= LogLevel.Warn) {
|
|
28480
|
-
this.provider.warn(message, this.serializeMeta(meta));
|
|
28481
|
-
}
|
|
28482
|
-
}
|
|
28483
|
-
error(message, meta) {
|
|
28484
|
-
if (this.options.enabled && this.options.level <= LogLevel.Error) {
|
|
28485
|
-
this.provider.error(message, this.serializeMeta(meta));
|
|
28486
|
-
}
|
|
28487
|
-
}
|
|
28488
|
-
fatal(message, meta) {
|
|
28489
|
-
if (this.options.enabled && this.options.level <= LogLevel.Fatal) {
|
|
28490
|
-
this.provider.fatal(message, this.serializeMeta(meta));
|
|
28491
|
-
}
|
|
28492
|
-
}
|
|
28493
|
-
exception(message, error, meta) {
|
|
28494
|
-
if (this.options.enabled && this.options.level <= LogLevel.Error) {
|
|
28495
|
-
this.provider.exception(message, error, this.serializeMeta(meta));
|
|
28496
|
-
}
|
|
28497
|
-
}
|
|
28498
|
-
serializeMeta(meta) {
|
|
28435
|
+
serializeMeta(options, meta) {
|
|
28499
28436
|
const serializedMeta = meta
|
|
28500
28437
|
? jsonSerialize(meta, {
|
|
28501
28438
|
prettify: true,
|
|
28502
28439
|
stripBinaryData: true,
|
|
28503
28440
|
})
|
|
28504
28441
|
: undefined;
|
|
28505
|
-
switch (
|
|
28442
|
+
switch (options.serialization) {
|
|
28506
28443
|
case MetaSerializationType.JSON:
|
|
28507
28444
|
return serializedMeta;
|
|
28508
28445
|
case MetaSerializationType.None:
|
|
@@ -28511,35 +28448,16 @@ class InternalLogger {
|
|
|
28511
28448
|
}
|
|
28512
28449
|
}
|
|
28513
28450
|
}
|
|
28514
|
-
const getLogger = ({ options, loggerName, }) => {
|
|
28515
|
-
return new InternalLogger(options, new DefaultLogger(loggerName));
|
|
28516
|
-
};
|
|
28517
28451
|
class Log {
|
|
28518
|
-
static
|
|
28519
|
-
this.
|
|
28520
|
-
}
|
|
28521
|
-
static setLevel(level) {
|
|
28522
|
-
this.options.level = level;
|
|
28523
|
-
this.options.level = level;
|
|
28524
|
-
this.options.enabled = true;
|
|
28525
|
-
}
|
|
28526
|
-
static enable() {
|
|
28527
|
-
this.options.enabled = true;
|
|
28528
|
-
}
|
|
28529
|
-
static disable() {
|
|
28530
|
-
this.options.enabled = false;
|
|
28452
|
+
static configure(instance) {
|
|
28453
|
+
this.container.instances.push(instance);
|
|
28531
28454
|
}
|
|
28532
28455
|
static getLogger(loggerName) {
|
|
28533
|
-
return
|
|
28534
|
-
options: this.options,
|
|
28535
|
-
loggerName,
|
|
28536
|
-
});
|
|
28456
|
+
return new InternalLogger(loggerName, this.container);
|
|
28537
28457
|
}
|
|
28538
28458
|
}
|
|
28539
|
-
Log.
|
|
28540
|
-
|
|
28541
|
-
level: LogLevel.Debug,
|
|
28542
|
-
serialization: MetaSerializationType.None,
|
|
28459
|
+
Log.container = {
|
|
28460
|
+
instances: [],
|
|
28543
28461
|
};
|
|
28544
28462
|
|
|
28545
28463
|
const logMemoryUsage = () => {
|