From d833914888da8211b717a6a07652aa214d0ce9ef Mon Sep 17 00:00:00 2001 From: martmull Date: Thu, 22 Jan 2026 13:38:45 +0100 Subject: [PATCH] Disable query logs if I want to (#17329) As tile --- .../twenty-config/config-variables.ts | 13 ++++++++ ...st-to-typeorm-log-level-array.decorator.ts | 30 +++++++++++++++++++ .../twenty-config/twenty-config.service.ts | 11 +------ 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 packages/twenty-server/src/engine/core-modules/twenty-config/decorators/cast-to-typeorm-log-level-array.decorator.ts diff --git a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts index dda2f62bfa..cb0905e966 100644 --- a/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts +++ b/packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts @@ -10,6 +10,7 @@ import { validateSync, } from 'class-validator'; import { isDefined } from 'twenty-shared/utils'; +import { type LoggerOptions } from 'typeorm/logger/LoggerOptions'; import { type AwsRegion } from 'src/engine/core-modules/twenty-config/interfaces/aws-region.interface'; import { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface'; @@ -24,6 +25,7 @@ import { LoggerDriverType } from 'src/engine/core-modules/logger/interfaces'; import { type MeterDriver } from 'src/engine/core-modules/metrics/types/meter-driver.type'; import { ServerlessDriverType } from 'src/engine/core-modules/serverless/serverless.interface'; import { CastToLogLevelArray } from 'src/engine/core-modules/twenty-config/decorators/cast-to-log-level-array.decorator'; +import { CastToTypeORMLogLevelArray } from 'src/engine/core-modules/twenty-config/decorators/cast-to-typeorm-log-level-array.decorator'; import { CastToMeterDriverArray } from 'src/engine/core-modules/twenty-config/decorators/cast-to-meter-driver.decorator'; import { CastToPositiveNumber } from 'src/engine/core-modules/twenty-config/decorators/cast-to-positive-number.decorator'; import { CastToUpperSnakeCase } from 'src/engine/core-modules/twenty-config/decorators/cast-to-upper-snake-case.decorator'; @@ -589,6 +591,17 @@ export class ConfigVariables { @IsOptional() TELEMETRY_ENABLED = true; + @ConfigVariablesMetadata({ + group: ConfigVariablesGroup.LOGGING, + description: + 'TypeORM logging options for development mode. Accepts comma-separated values: query, schema, error, warn, info, log, migration', + type: ConfigVariableType.ARRAY, + options: ['query', 'schema', 'error', 'warn', 'info', 'log', 'migration'], + }) + @CastToTypeORMLogLevelArray() + @IsOptional() + TYPEORM_LOGGING: LoggerOptions = ['error']; + @ConfigVariablesMetadata({ group: ConfigVariablesGroup.BILLING_CONFIG, description: 'Enable or disable billing features', diff --git a/packages/twenty-server/src/engine/core-modules/twenty-config/decorators/cast-to-typeorm-log-level-array.decorator.ts b/packages/twenty-server/src/engine/core-modules/twenty-config/decorators/cast-to-typeorm-log-level-array.decorator.ts new file mode 100644 index 0000000000..eec3752ab0 --- /dev/null +++ b/packages/twenty-server/src/engine/core-modules/twenty-config/decorators/cast-to-typeorm-log-level-array.decorator.ts @@ -0,0 +1,30 @@ +import { Transform } from 'class-transformer'; +import { isNonEmptyString } from '@sniptt/guards'; + +export const CastToTypeORMLogLevelArray = () => + Transform(({ value }: { value: string }) => toTypeORMLogLevelArray(value)); + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const toTypeORMLogLevelArray = (value: any) => { + if (isNonEmptyString(value)) { + const rawLogLevels = value.split(',').map((level) => level.trim()); + const validLevels = [ + 'query', + 'schema', + 'error', + 'warn', + 'info', + 'log', + 'migration', + ]; + const isInvalid = rawLogLevels.some( + (level) => !validLevels.includes(level), + ); + + if (!isInvalid) { + return rawLogLevels; + } + } + + return undefined; +}; diff --git a/packages/twenty-server/src/engine/core-modules/twenty-config/twenty-config.service.ts b/packages/twenty-server/src/engine/core-modules/twenty-config/twenty-config.service.ts index d200a46b53..3f1b21653d 100644 --- a/packages/twenty-server/src/engine/core-modules/twenty-config/twenty-config.service.ts +++ b/packages/twenty-server/src/engine/core-modules/twenty-config/twenty-config.service.ts @@ -3,8 +3,6 @@ import { Injectable, Logger, Optional } from '@nestjs/common'; import { isString } from 'class-validator'; import { type LoggerOptions } from 'typeorm/logger/LoggerOptions'; -import { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface'; - import { ConfigVariables } from 'src/engine/core-modules/twenty-config/config-variables'; import { CONFIG_VARIABLES_MASKING_CONFIG } from 'src/engine/core-modules/twenty-config/constants/config-variables-masking-config'; import { type ConfigVariablesMetadataOptions } from 'src/engine/core-modules/twenty-config/decorators/config-variables-metadata.decorator'; @@ -200,14 +198,7 @@ export class TwentyConfigService { } getLoggingConfig(): LoggerOptions { - switch (this.get('NODE_ENV')) { - case NodeEnvironment.DEVELOPMENT: - return ['query', 'error']; - case NodeEnvironment.TEST: - return []; - default: - return ['error']; - } + return this.get('TYPEORM_LOGGING'); } private validateNotEnvOnly(