2020-06-13 10:43:02 +00:00
|
|
|
import * as plugins from './smartfile-destination-file.plugins';
|
|
|
|
|
2020-06-13 11:03:08 +00:00
|
|
|
export class SmartlogDestinationFile implements plugins.smartlogInterfaces.ILogDestination {
|
2020-06-15 15:16:47 +00:00
|
|
|
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`);
|
2020-06-13 11:03:08 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 15:16:47 +00:00
|
|
|
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}"`);
|
|
|
|
}
|
|
|
|
plugins.smartfile.fs.ensureFileSync(filePathArg, `# Smartlogfile. Created at ${extendedDate.toISOString()}\n`);
|
|
|
|
this.fileWriteStream = plugins.fs.createWriteStream(
|
|
|
|
filePathArg,
|
|
|
|
{
|
|
|
|
flags: 'a+',
|
|
|
|
}
|
|
|
|
);
|
2020-06-13 11:03:08 +00:00
|
|
|
}
|
|
|
|
}
|