diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-01-24 18:59:13 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-01-24 18:59:13 -0700 |
commit | 203925d9a48d34537bdf6cd25502134df5e91ae7 (patch) | |
tree | afe8a12679568ba00bfa019b0a5b6f13a3778c00 /src/utils | |
download | tabloid-compiler-main.tar.gz tabloid-compiler-main.zip |
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/index.ts | 1 | ||||
-rw-r--r-- | src/utils/logger.ts | 35 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 0000000..1ff09ef --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1 @@ +export * from './logger'; diff --git a/src/utils/logger.ts b/src/utils/logger.ts new file mode 100644 index 0000000..11a24f7 --- /dev/null +++ b/src/utils/logger.ts @@ -0,0 +1,35 @@ +export interface TracingLogger { + info(log: string): void; + warn(log: string): void; + error(log: string): void; + + createChild(prefix: string): TracingLogger; +} + +export class ConsoleTracingLogger implements TracingLogger { + protected prefix: string; + + constructor(prefix: string) { + this.prefix = prefix; + } + + private makePrefix(level: 'info' | 'warn' | 'error'): string { + return `[${new Date().toISOString()}] ${level} (${this.prefix}) > `; + } + + public info(log: string) { + console.log(this.makePrefix('info') + log); + } + + public warn(log: string) { + console.warn(this.makePrefix('warn') + log); + } + + public error(log: string) { + console.error(this.makePrefix('error') + log); + } + + public createChild(prefix: string) { + return new ConsoleTracingLogger(`${this.prefix} -> ${prefix}`); + } +} |