From f97852a8b9301e84056daec676126bda6187c81f Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Fri, 17 May 2024 17:46:57 +0545 Subject: [PATCH] feat(logging)!: drop `logFile` and `logFileLevel` (#29104) Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com> --- docs/usage/self-hosted-configuration.md | 3 --- lib/config/options/index.ts | 19 ------------- lib/config/types.ts | 3 --- lib/config/validation.spec.ts | 16 ++++++----- lib/config/validation.ts | 3 +-- lib/workers/global/config/parse/file.spec.ts | 1 - lib/workers/global/config/parse/index.spec.ts | 27 +++---------------- lib/workers/global/config/parse/index.ts | 23 ++-------------- 8 files changed, 17 insertions(+), 78 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 5c361bb702b0a5..2fbe0ecb3c380c 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -757,9 +757,6 @@ When you set `inheritConfigStrict=true` then Renovate will abort the run and rai `logContext` is included with each log entry only if `logFormat="json"` - it is not included in the pretty log output. If left as default (null), a random short ID will be selected. -## logFile - -## logFileLevel ## mergeConfidenceDatasources diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index b9674ab0909c9d..71173ff0283f6a 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -542,25 +542,6 @@ const options: RenovateOptions[] = [ supportedManagers: ['gomod'], }, // Log options - { - name: 'logFile', - description: 'Log file path.', - stage: 'global', - type: 'string', - globalOnly: true, - deprecationMsg: - 'Instead of configuring log file path in the file config. Use the `LOG_FILE` environment variable instead.', - }, - { - name: 'logFileLevel', - description: 'Set the log file log level.', - stage: 'global', - type: 'string', - default: 'debug', - globalOnly: true, - deprecationMsg: - 'Instead of configuring log file level in the file config. Use the `LOG_FILE_LEVEL` environment variable instead.', - }, { name: 'logContext', description: 'Add a global or per-repo log context to each log entry.', diff --git a/lib/config/types.ts b/lib/config/types.ts index f2e3220c03b1da..76e7079b0aa4b5 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -1,4 +1,3 @@ -import type { LogLevel } from 'bunyan'; import type { PlatformId } from '../constants'; import type { LogLevelRemap } from '../logger/types'; import type { CustomManager } from '../modules/manager/custom/types'; @@ -114,8 +113,6 @@ export interface GlobalOnlyConfig { gitNoVerify?: GitNoVerifyOption[]; gitPrivateKey?: string; globalExtends?: string[]; - logFile?: string; - logFileLevel?: LogLevel; mergeConfidenceDatasources?: string[]; mergeConfidenceEndpoint?: string; platform?: PlatformId; diff --git a/lib/config/validation.spec.ts b/lib/config/validation.spec.ts index e11f6bbba57070..71e97eeb230068 100644 --- a/lib/config/validation.spec.ts +++ b/lib/config/validation.spec.ts @@ -1306,19 +1306,23 @@ describe('config/validation', () => { }); describe('validateConfig() -> globaOnly options', () => { - it('returns deprecation warnings', async () => { + it('returns errors for invalid options', async () => { const config = { logFile: 'something', + logFileLevel: 'DEBUG', }; - const { warnings } = await configValidation.validateConfig( + const { errors } = await configValidation.validateConfig( 'global', config, ); - expect(warnings).toMatchObject([ + expect(errors).toMatchObject([ { - message: - 'Using logFile to specify log file name is deprecated now. Please use the enviroment variable LOG_FILE instead', - topic: 'Deprecation Warning', + message: 'Invalid configuration option: logFile', + topic: 'Configuration Error', + }, + { + message: 'Invalid configuration option: logFileLevel', + topic: 'Configuration Error', }, ]); }); diff --git a/lib/config/validation.ts b/lib/config/validation.ts index 4685a01b9db74e..7e4d4d8cf6d159 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -100,8 +100,6 @@ function getDeprecationMessage(option: string): string | undefined { branchName: `Direct editing of branchName is now deprecated. Please edit branchPrefix, additionalBranchPrefix, or branchTopic instead`, commitMessage: `Direct editing of commitMessage is now deprecated. Please edit commitMessage's subcomponents instead.`, prTitle: `Direct editing of prTitle is now deprecated. Please edit commitMessage subcomponents instead as they will be passed through to prTitle.`, - logFile: `Using logFile to specify log file name is deprecated now. Please use the enviroment variable LOG_FILE instead`, - logFileLevel: `Using logFileLevel to specify log level for file logging is deprecated now. Please use the enviroment variable LOG_FILE_LEVEL instead`, }; return deprecatedOptions[option]; } @@ -880,6 +878,7 @@ async function validateGlobalConfig( currentPath: string | undefined, config: RenovateConfig, ): Promise { + // istanbul ignore if if (getDeprecationMessage(key)) { warnings.push({ topic: 'Deprecation Warning', diff --git a/lib/workers/global/config/parse/file.spec.ts b/lib/workers/global/config/parse/file.spec.ts index 822f67bda24e1a..89f92f183268f1 100644 --- a/lib/workers/global/config/parse/file.spec.ts +++ b/lib/workers/global/config/parse/file.spec.ts @@ -75,7 +75,6 @@ describe('workers/global/config/parse/file', () => { `module.exports = { "platform": "github", "token":"abcdef", - "logFileLevel": "warn", "onboarding": false, "gitAuthor": "Renovate Bot " "onboardingConfig": { diff --git a/lib/workers/global/config/parse/index.spec.ts b/lib/workers/global/config/parse/index.spec.ts index d13081cc8f9440..54321079d6528e 100644 --- a/lib/workers/global/config/parse/index.spec.ts +++ b/lib/workers/global/config/parse/index.spec.ts @@ -173,30 +173,11 @@ describe('workers/global/config/parse/index', () => { expect(parsed).toContainEntries([['dryRun', null]]); }); - it('initalizes file logging when logFile is set and env vars LOG_FILE is undefined', async () => { - jest.doMock( - '../../../../../config.js', - () => ({ logFile: 'somepath', logFileLevel: 'debug' }), - { - virtual: true, - }, - ); - const env: NodeJS.ProcessEnv = {}; - const parsedConfig = await configParser.parseConfigs(env, defaultArgv); - expect(parsedConfig).not.toContain([['logFile', 'someFile']]); - expect(getParentDir).toHaveBeenCalledWith('somepath'); - }); - - it('skips initializing file logging when logFile is set but env vars LOG_FILE is defined', async () => { - jest.doMock( - '../../../../../config.js', - () => ({ logFile: 'somepath', logFileLevel: 'debug' }), - { - virtual: true, - }, - ); + it('only initializes the file when the env var LOG_FILE is properly set', async () => { + jest.doMock('../../../../../config.js', () => ({}), { + virtual: true, + }); const env: NodeJS.ProcessEnv = {}; - process.env.LOG_FILE = 'somepath'; const parsedConfig = await configParser.parseConfigs(env, defaultArgv); expect(parsedConfig).not.toContain([['logFile', 'someFile']]); expect(getParentDir).not.toHaveBeenCalled(); diff --git a/lib/workers/global/config/parse/index.ts b/lib/workers/global/config/parse/index.ts index 6d51625ace451a..520321f681558a 100644 --- a/lib/workers/global/config/parse/index.ts +++ b/lib/workers/global/config/parse/index.ts @@ -1,11 +1,10 @@ -import is from '@sindresorhus/is'; import * as defaultsParser from '../../../../config/defaults'; import type { AllConfig } from '../../../../config/types'; import { mergeChildConfig } from '../../../../config/utils'; -import { addStream, logger, setContext } from '../../../../logger'; +import { logger, setContext } from '../../../../logger'; import { detectAllGlobalConfig } from '../../../../modules/manager'; import { coerceArray } from '../../../../util/array'; -import { ensureDir, getParentDir, readSystemFile } from '../../../../util/fs'; +import { readSystemFile } from '../../../../util/fs'; import { addSecretForSanitizing } from '../../../../util/sanitize'; import { ensureTrailingSlash } from '../../../../util/url'; import * as cliParser from './cli'; @@ -67,20 +66,6 @@ export async function parseConfigs( setContext(config.logContext); } - // Add file logger - if (config.logFile && is.undefined(process.env.LOG_FILE)) { - logger.debug( - // TODO: types (#22198) - `Enabling ${config.logFileLevel!} logging to ${config.logFile}`, - ); - await ensureDir(getParentDir(config.logFile)); - addStream({ - name: 'logfile', - path: config.logFile, - level: config.logFileLevel, - }); - } - logger.trace({ config: defaultConfig }, 'Default config'); logger.debug({ config: fileConfig }, 'File config'); logger.debug({ config: cliConfig }, 'CLI config'); @@ -119,9 +104,5 @@ export async function parseConfigs( config.onboardingNoDeps = 'enabled'; } - // Remove log file entries - delete config.logFile; - delete config.logFileLevel; - return config; }