2026-04-07 15:58:41 +00:00
|
|
|
import * as plugins from './plugins.js';
|
2025-05-12 10:03:22 +00:00
|
|
|
|
|
|
|
|
export class SmartlogDestinationFile implements plugins.smartlogInterfaces.ILogDestination {
|
|
|
|
|
public fileWriteStream: plugins.fs.WriteStream;
|
|
|
|
|
|
|
|
|
|
public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
|
|
|
|
this.fileWriteStream.write(`${new plugins.smarttime.ExtendedDate(Date.now()).toISOString()}: ${logPackageArg.message} \n`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(filePathArg: string) {
|
|
|
|
|
const extendedDate = new plugins.smarttime.ExtendedDate(Date.now());
|
|
|
|
|
if (!plugins.path.isAbsolute(filePathArg)) {
|
|
|
|
|
throw new Error(`filePath needs to be absolute but is not: "${filePathArg}"`);
|
|
|
|
|
}
|
2026-04-07 15:58:41 +00:00
|
|
|
if (!plugins.fs.existsSync(filePathArg)) {
|
|
|
|
|
plugins.fs.mkdirSync(plugins.path.dirname(filePathArg), { recursive: true });
|
|
|
|
|
plugins.fs.writeFileSync(filePathArg, `# Smartlogfile. Created at ${extendedDate.toISOString()}\n`);
|
|
|
|
|
}
|
2025-05-12 10:03:22 +00:00
|
|
|
this.fileWriteStream = plugins.fs.createWriteStream(
|
|
|
|
|
filePathArg,
|
|
|
|
|
{
|
|
|
|
|
flags: 'a+',
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|