|
|
@@ -1,17 +1,31 @@
|
|
|
/**
|
|
|
* Simple logger that outputs to stdout and stderr
|
|
|
* Compatible with systemd/journalctl
|
|
|
+ *
|
|
|
+ * When running under systemd, timestamps are omitted since systemd
|
|
|
+ * adds its own timestamps to avoid duplication.
|
|
|
*/
|
|
|
export class Logger {
|
|
|
private prefix: string;
|
|
|
+ private isSystemd: boolean;
|
|
|
|
|
|
constructor(prefix: string = 'WebshopScraper') {
|
|
|
this.prefix = prefix;
|
|
|
+ // Detect if running under systemd by checking for INVOCATION_ID
|
|
|
+ // This environment variable is set by systemd for each service invocation
|
|
|
+ this.isSystemd = !!process.env.INVOCATION_ID;
|
|
|
}
|
|
|
|
|
|
private formatMessage(level: string, message: string, ...args: any[]): string {
|
|
|
- const timestamp = new Date().toISOString();
|
|
|
const formattedArgs = args.length > 0 ? ' ' + JSON.stringify(args) : '';
|
|
|
+
|
|
|
+ // When running under systemd, omit timestamp as systemd adds its own
|
|
|
+ if (this.isSystemd) {
|
|
|
+ return `[${level}] [${this.prefix}] ${message}${formattedArgs}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Include timestamp for non-systemd environments (dev, manual runs)
|
|
|
+ const timestamp = new Date().toISOString();
|
|
|
return `[${timestamp}] [${level}] [${this.prefix}] ${message}${formattedArgs}`;
|
|
|
}
|
|
|
|