feat: workspace:health nullable fix (#3882)
This commit is contained in:
38
packages/twenty-server/src/commands/command-logger.ts
Normal file
38
packages/twenty-server/src/commands/command-logger.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { existsSync } from 'fs';
|
||||
import fs from 'fs/promises';
|
||||
|
||||
import { kebabCase } from 'src/utils/kebab-case';
|
||||
|
||||
@Injectable()
|
||||
export class CommandLogger {
|
||||
constructor(private readonly className: string) {}
|
||||
|
||||
async writeLog(
|
||||
fileName: string,
|
||||
data: unknown,
|
||||
append: boolean = false,
|
||||
): Promise<void> {
|
||||
const path = `./logs/${kebabCase(this.className)}`;
|
||||
|
||||
if (existsSync(path) === false) {
|
||||
await fs.mkdir(path, { recursive: true });
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.writeFile(
|
||||
`${path}/${fileName}.json`,
|
||||
JSON.stringify(data, null, 2),
|
||||
{
|
||||
flag: append ? 'a' : 'w',
|
||||
},
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`Error writing to file ${path}/${fileName}.json: ${err?.message}`,
|
||||
);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user