From cf29c338090a09cf209f772cd18f28943f4a9f7a Mon Sep 17 00:00:00 2001
From: RahulGautamSingh <rahultesnik@gmail.com>
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 738d5e61ec..3bc0447d79 100644
--- a/docs/usage/self-hosted-configuration.md
+++ b/docs/usage/self-hosted-configuration.md
@@ -761,9 +761,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 3919e0c8fc..6d84cc5abe 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 3d58ebb42e..ae210f7dbe 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';
@@ -115,8 +114,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 57e646b393..26e815d3a7 100644
--- a/lib/config/validation.spec.ts
+++ b/lib/config/validation.spec.ts
@@ -1383,19 +1383,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 31cd2ad44b..ab2f8c390a 100644
--- a/lib/config/validation.ts
+++ b/lib/config/validation.ts
@@ -129,8 +129,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];
 }
@@ -923,6 +921,7 @@ async function validateGlobalConfig(
   currentPath: string | undefined,
   config: RenovateConfig,
 ): Promise<void> {
+  // 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 822f67bda2..89f92f1832 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 <renovate@whitesourcesoftware.com>"
         "onboardingConfig": {
diff --git a/lib/workers/global/config/parse/index.spec.ts b/lib/workers/global/config/parse/index.spec.ts
index d13081cc8f..54321079d6 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 6d51625ace..520321f681 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;
 }
-- 
GitLab