-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8a6281
commit 1b3c1a5
Showing
19 changed files
with
133 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import { Logger } from "./logger.ts"; | ||
import { BaseLogger } from "./base.logger.ts"; | ||
import type { LogLevel } from "./logLevel.ts"; | ||
import type { ILogger } from "./logger.interface.ts"; | ||
import type { Logger } from "./logger.interface.ts"; | ||
|
||
export class AggregateLogger extends Logger { | ||
private readonly loggers: ILogger[]; | ||
constructor(...loggers: ILogger[]) { | ||
export class AggregateLogger extends BaseLogger { | ||
private readonly loggers: Logger[]; | ||
constructor(...loggers: Logger[]) { | ||
super(); | ||
this.loggers = [...loggers]; | ||
} | ||
public async log( | ||
level: LogLevel, | ||
name: string, | ||
message: string, | ||
data: Record<string, unknown>, | ||
data: Record<keyof unknown, unknown>, | ||
) { | ||
await Promise.all( | ||
this.loggers.map((logger) => logger.log(level, name, message, data)), | ||
this.loggers.map((logger) => logger.log(level, message, data)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { LogLevel } from "./logLevel.ts"; | ||
import type { Logger } from "./logger.interface.ts"; | ||
|
||
export abstract class BaseLogger implements Logger { | ||
public abstract log( | ||
level: LogLevel, | ||
message: string, | ||
data: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
|
||
public async trace( | ||
message: string, | ||
data: Record<keyof unknown, unknown> = {}, | ||
) { | ||
await this.log(LogLevel.Trace, message, data); | ||
} | ||
|
||
public async debug( | ||
message: string, | ||
data: Record<keyof unknown, unknown> = {}, | ||
) { | ||
await this.log(LogLevel.Debug, message, data); | ||
} | ||
|
||
public async warn( | ||
message: string, | ||
data: Record<keyof unknown, unknown> = {}, | ||
) { | ||
await this.log(LogLevel.Warn, message, data); | ||
} | ||
|
||
public async info( | ||
message: string, | ||
data: Record<keyof unknown, unknown> = {}, | ||
) { | ||
await this.log(LogLevel.Info, message, data); | ||
} | ||
|
||
public async error( | ||
message: string, | ||
error: unknown, | ||
data: Record<keyof unknown, unknown> = {}, | ||
) { | ||
await this.log(LogLevel.Error, message, { | ||
...data, | ||
error, | ||
}); | ||
} | ||
|
||
public async critical( | ||
message: string, | ||
data: Record<keyof unknown, unknown> = {}, | ||
) { | ||
await this.log(LogLevel.Critical, message, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
import type { LogLevel } from "./logLevel.ts"; | ||
|
||
export interface ILogger { | ||
export type Logger = { | ||
log( | ||
level: LogLevel, | ||
name: string, | ||
message: string, | ||
data?: Record<string, unknown>, | ||
data?: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
trace( | ||
name: string, | ||
message: string, | ||
data?: Record<string, unknown>, | ||
data?: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
debug( | ||
name: string, | ||
message: string, | ||
data?: Record<string, unknown>, | ||
data?: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
warn( | ||
name: string, | ||
message: string, | ||
data?: Record<string, unknown>, | ||
data?: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
info( | ||
name: string, | ||
message: string, | ||
data?: Record<string, unknown>, | ||
data?: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
error( | ||
name: string, | ||
message: string, | ||
error: Error, | ||
data?: Record<string, unknown>, | ||
error: unknown, | ||
data?: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
critical( | ||
name: string, | ||
message: string, | ||
data?: Record<string, unknown>, | ||
data?: Record<keyof unknown, unknown>, | ||
): Promise<void>; | ||
} | ||
}; |
Oops, something went wrong.