diff --git a/packages/core/src/logger.ts b/packages/core/src/logger.ts index f8172d0b6ca..ae9b3a19852 100644 --- a/packages/core/src/logger.ts +++ b/packages/core/src/logger.ts @@ -1,4 +1,11 @@ -class ElizaLogger { +import settings from "./settings.ts"; +import { Logger, ILogObjMeta, ILogObj } from "tslog"; + +interface IElizaLogger extends Logger { + 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 log(...strings) { this.#logWithStyle(strings, { fg: "white", @@ -182,6 +190,7 @@ class ElizaLogger { }); } + // @ts-ignore - custom implementation warn(...strings) { this.#logWithStyle(strings, { fg: "yellow", @@ -191,6 +200,7 @@ class ElizaLogger { }); } + // @ts-ignore - custom implementation error(...strings) { this.#logWithStyle(strings, { fg: "red", @@ -200,6 +210,7 @@ class ElizaLogger { }); } + // @ts-ignore - custom implementation 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 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();