Skip to content

Commit

Permalink
Added datettime to all headless logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Inrixia committed Apr 5, 2024
1 parent 9fe17e9 commit 0783880
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ process.on("SIGTERM", process.exit);
const waitLoop = async () => {
await downloadNewVideos();
setTimeout(waitLoop, 5 * 60 * 1000);
console.log("[" + new Date().toLocaleTimeString() + "]" + " Checking for new videos in 5 minutes...");
console.log(`${args.headless ? `[${new Date().toLocaleString()}]` : ""} Checking for new videos in 5 minutes...`);
};
waitLoop();
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ recursiveUpdate(settings, env, { setUndefined: false, setDefined: true });

export const args = { ...argv, ...env };

// eslint-disable-next-line no-control-regex
const headlessStdoutRegex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
// Override stdout if headless to not include formatting tags
if (args.headless === true) {
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
type StdoutArgs = Parameters<typeof process.stdout.write>;

process.stdout.write = ((...params: StdoutArgs) => {
// eslint-disable-next-line no-control-regex
if (typeof params[0] === "string") params[0] = params[0].replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
if (typeof params[0] === "string") params[0] = `[${new Date().toLocaleString()}] ${params[0].replace(headlessStdoutRegex, "")}`;
return originalStdoutWrite(...params);
}) as typeof process.stdout.write;
}

0 comments on commit 0783880

Please sign in to comment.