Skip to content

Commit

Permalink
fix: save log to tmp dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed Feb 4, 2025
1 parent 1e5d28c commit b92e8df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/core/src/test-utils/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ beforeAll(() => {
console.debug = jest.fn();
process.stdout.write = jest.fn();
process.stderr.write = jest.fn();
jest.spyOn(logger, "writeLogsToFile").mockImplementation(() => {});
});

afterAll(() => {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/utils/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
LoggerOperationResultType,
} from "@/types/logger";
import * as fs from "fs";
import path from "path";
import os from "os";

class Logger {
private static instance: Logger;
Expand Down Expand Up @@ -169,8 +171,9 @@ class Logger {

public writeLogsToFile(filename: string): void {
try {
fs.writeFileSync(filename, this.logs.join("\n"), "utf8");
this.info(`💾 Logs have been written to ${filename}`);
const tempFilePath = path.join(os.tmpdir(), filename);
fs.writeFileSync(tempFilePath, this.logs.join("\n"), "utf8");
this.info(`💾 Logs have been written to ${tempFilePath}`);
} catch (err) {
this.error("Failed to write logs to file:", {
message: `${(err as Error).message}`,
Expand Down

0 comments on commit b92e8df

Please sign in to comment.