Skip to content

Commit

Permalink
fix: missing updates for logger.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yodamaster726 committed Nov 23, 2024
1 parent 93608e0 commit 644ebb2
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions packages/core/src/logger.ts
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

View workflow job for this annotation

GitHub Actions / check

'ILogObjMeta' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 2 in packages/core/src/logger.ts

View workflow job for this annotation

GitHub Actions / check

'ILogObj' is defined but never used. Allowed unused vars must match /^_/u

interface IElizaLogger extends Logger<IElizaLogger> {
progress(message: string): void;
}

class ElizaLogger implements IElizaLogger {
constructor() {
// Check if we're in Node.js environment
this.isNode =
Expand All @@ -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;
Expand Down Expand Up @@ -173,6 +180,7 @@ class ElizaLogger {
}
}

// @ts-ignore - custom implementation

Check failure on line 183 in packages/core/src/logger.ts

View workflow job for this annotation

GitHub Actions / check

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
log(...strings) {
this.#logWithStyle(strings, {
fg: "white",
Expand All @@ -182,6 +190,7 @@ class ElizaLogger {
});
}

// @ts-ignore - custom implementation

Check failure on line 193 in packages/core/src/logger.ts

View workflow job for this annotation

GitHub Actions / check

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
warn(...strings) {
this.#logWithStyle(strings, {
fg: "yellow",
Expand All @@ -191,6 +200,7 @@ class ElizaLogger {
});
}

// @ts-ignore - custom implementation

Check failure on line 203 in packages/core/src/logger.ts

View workflow job for this annotation

GitHub Actions / check

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
error(...strings) {
this.#logWithStyle(strings, {
fg: "red",
Expand All @@ -200,6 +210,7 @@ class ElizaLogger {
});
}

// @ts-ignore - custom implementation

Check failure on line 213 in packages/core/src/logger.ts

View workflow job for this annotation

GitHub Actions / check

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
info(...strings) {
this.#logWithStyle(strings, {
fg: "blue",
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / check

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
debug(...strings) {
if (!this.verbose) return;
this.#logWithStyle(strings, {
Expand All @@ -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",
Expand All @@ -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();
Expand Down

0 comments on commit 644ebb2

Please sign in to comment.