Files
twenty/packages/twenty-server/src/database/commands/logger.ts
T
Paul Rastoin 442f8dbe3c [QRQC_2] No implicitAny in twenty-server (#12075)
# Introduction
Following https://github.com/twentyhq/twenty/pull/12068
Related with https://github.com/twentyhq/core-team-issues/issues/975

We're enabling `noImplicitAny` handled few use case manually, added a
`ts-expect-error` to the others, we should plan to handle them in the
future
2025-05-15 18:23:22 +02:00

54 lines
1.5 KiB
TypeScript

import { Logger } from '@nestjs/common';
interface CommandLoggerOptions {
verbose?: boolean;
constructorName: string;
}
export const isCommandLogger = (
logger: Logger | CommandLogger,
): logger is CommandLogger => {
// @ts-expect-error legacy noImplicitAny
return typeof logger['setVerbose'] === 'function';
};
export class CommandLogger {
private logger: Logger;
private verboseFlag: boolean;
constructor(options: CommandLoggerOptions) {
this.logger = new Logger(options.constructorName);
this.verboseFlag = options.verbose ?? false;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
log(message: string, ...optionalParams: [...any, string?]) {
this.logger.log(message, ...optionalParams);
}
error(message: string, stack?: string, context?: string) {
this.logger.error(message, stack, context);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
warn(message: string, ...optionalParams: [...any, string?]) {
this.logger.warn(message, ...optionalParams);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
debug(message: string, ...optionalParams: [...any, string?]) {
this.logger.debug(message, ...optionalParams);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
verbose(message: string, ...optionalParams: [...any, string?]) {
if (this.verboseFlag) {
this.logger.log(message, ...optionalParams);
}
}
setVerbose(flag: boolean) {
this.verboseFlag = flag;
}
}