Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gregemax committed Sep 21, 2024
1 parent c3d1abb commit 480463b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
1 change: 1 addition & 0 deletions packages/node/logs/debug.log
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
[DEBUG] 2024-09-20T19:10:56.715Z - test::debug This should appear
[DEBUG] 2024-09-20T19:11:09.339Z - test::debug This should appear
[DEBUG] 2024-09-20T19:16:33.775Z - test::debug This should appear
[DEBUG] 2024-09-21T10:39:53.270Z - test::debug This should appear
2 changes: 1 addition & 1 deletion packages/node/src/utility/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from "node:fs";


export class Logger {
private static debugMode: boolean = false;
private static debugMode: string|boolean = process.env.debugMode || false;

static logToFile(message: string) {
const logFilePath = "logs/debug.log";
Expand Down
14 changes: 7 additions & 7 deletions packages/node/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { test, expect, vi } from "vitest";
import { Logger } from "../src/utility/utility"; // Adjust the path to your Logger

test("Logger.debug should not log when debug mode is off", () => {
// Mock console.log to spy on its calls

const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});

// Set DEBUG_MODE to false
Logger.setDebugMode(false); // Assuming Logger has a method to set debug mode

Logger.setDebugMode(false);

// Call Logger.debug

Logger.debug("test::debug", "This should not appear");

// Assert that console.log wasn't called

expect(logSpy).not.toHaveBeenCalled();

// Clean up the mock

logSpy.mockRestore();
});

Expand All @@ -34,6 +34,6 @@ test("Logger.debug should log when debug mode is on", () => {
)
);

// Clean up the mock

logSpy.mockRestore();
});
42 changes: 27 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 480463b

Please sign in to comment.