The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Disable query logs if I want to (#17329)
martmulld833914888da
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.tsindex dda2f62bfa6..cb0905e966f 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.tsnew file mode 100644index 00000000000..eec3752ab08--- /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.tsindex d200a46b53e..3f1b21653d3 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<T extends keyof ConfigVariables>(