-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
93608e0
commit 644ebb2
Showing
1 changed file
with
34 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
class ElizaLogger { | ||
import settings from "./settings.ts"; | ||
import { Logger, ILogObjMeta, ILogObj } from "tslog"; | ||
Check failure on line 2 in packages/core/src/logger.ts
|
||
|
||
interface IElizaLogger extends Logger<IElizaLogger> { | ||
progress(message: string): void; | ||
} | ||
|
||
class ElizaLogger implements IElizaLogger { | ||
constructor() { | ||
// Check if we're in Node.js environment | ||
this.isNode = | ||
|
@@ -7,7 +14,7 @@ class ElizaLogger { | |
process.versions.node != null; | ||
|
||
// Set verbose based on environment | ||
this.verbose = this.isNode ? process.env.verbose === "true" : false; | ||
this.verbose = this.isNode ? settings.VERBOSE === "true" : false; | ||
} | ||
|
||
private isNode: boolean; | ||
|
@@ -173,6 +180,7 @@ class ElizaLogger { | |
} | ||
} | ||
|
||
// @ts-ignore - custom implementation | ||
Check failure on line 183 in packages/core/src/logger.ts
|
||
log(...strings) { | ||
this.#logWithStyle(strings, { | ||
fg: "white", | ||
|
@@ -182,6 +190,7 @@ class ElizaLogger { | |
}); | ||
} | ||
|
||
// @ts-ignore - custom implementation | ||
Check failure on line 193 in packages/core/src/logger.ts
|
||
warn(...strings) { | ||
this.#logWithStyle(strings, { | ||
fg: "yellow", | ||
|
@@ -191,6 +200,7 @@ class ElizaLogger { | |
}); | ||
} | ||
|
||
// @ts-ignore - custom implementation | ||
Check failure on line 203 in packages/core/src/logger.ts
|
||
error(...strings) { | ||
this.#logWithStyle(strings, { | ||
fg: "red", | ||
|
@@ -200,6 +210,7 @@ class ElizaLogger { | |
}); | ||
} | ||
|
||
// @ts-ignore - custom implementation | ||
Check failure on line 213 in packages/core/src/logger.ts
|
||
info(...strings) { | ||
this.#logWithStyle(strings, { | ||
fg: "blue", | ||
|
@@ -209,15 +220,7 @@ class ElizaLogger { | |
}); | ||
} | ||
|
||
success(...strings) { | ||
this.#logWithStyle(strings, { | ||
fg: "green", | ||
bg: "", | ||
icon: "\u2713", | ||
groupTitle: ` ${this.successesTitle}`, | ||
}); | ||
} | ||
|
||
// @ts-ignore - custom implementation | ||
Check failure on line 223 in packages/core/src/logger.ts
|
||
debug(...strings) { | ||
if (!this.verbose) return; | ||
this.#logWithStyle(strings, { | ||
|
@@ -228,6 +231,15 @@ class ElizaLogger { | |
}); | ||
} | ||
|
||
success(...strings) { | ||
this.#logWithStyle(strings, { | ||
fg: "green", | ||
bg: "", | ||
icon: "\u2713", | ||
groupTitle: ` ${this.successesTitle}`, | ||
}); | ||
} | ||
|
||
assert(...strings) { | ||
this.#logWithStyle(strings, { | ||
fg: "cyan", | ||
|
@@ -236,6 +248,17 @@ class ElizaLogger { | |
groupTitle: ` ${this.assertsTitle}`, | ||
}); | ||
} | ||
|
||
progress(message: string) { | ||
if (this.isNode) { | ||
// Clear the current line and move cursor to beginning | ||
process.stdout.clearLine(0); | ||
process.stdout.cursorTo(0); | ||
process.stdout.write(message); | ||
} else { | ||
console.log(message); | ||
} | ||
} | ||
} | ||
|
||
export const elizaLogger = new ElizaLogger(); | ||
|