From 434fdbd4be9969bc0a8fb3f7f9fa0e26efe8da9f Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Tue, 19 Jan 2021 10:29:45 +0100
Subject: [PATCH] feat: deprecated logLevel option (#8301)

* feat: deprecated logLevel option

* feat: deprecated logLevel option

* docs: update logging

* fix: remove log level env option

* Update warn

Co-authored-by: Rhys Arkins <rhys@arkins.net>
---
 docs/development/configuration.md            |  3 ++-
 docs/usage/self-hosted-configuration.md      |  2 ++
 docs/usage/self-hosting.md                   |  2 --
 lib/config/config/__fixtures__/file.js       |  1 -
 lib/config/config/__fixtures__/with-force.js |  1 -
 lib/config/definitions.ts                    |  4 +---
 lib/config/file.spec.ts                      |  1 -
 lib/config/index.ts                          | 10 ++++++++--
 8 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/docs/development/configuration.md b/docs/development/configuration.md
index 8f50e1ba6a..549c44712c 100644
--- a/docs/development/configuration.md
+++ b/docs/development/configuration.md
@@ -38,7 +38,6 @@ e.g. apply one set of labels for `backend/package.json` and a different set of l
 module.exports = {
   npmrc: '//registry.npmjs.org/:_authToken=abc123',
   baseDir: '/tmp/renovate',
-  logLevel: 'debug',
   includeForks: true,
   gradle: { enabled: false },
 };
@@ -53,6 +52,8 @@ $ node renovate --help
 To configure any `<list>` items, separate with commas.
 E.g. `renovate --labels=renovate,dependency`.
 
+To enable debug logging export `LOG_LEVEL=debug` to your environment.
+
 ### renovate.json
 
 If you add a `renovate.json` file to the root of your repository, you can use this to override default settings.
diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md
index 2ccacf6d5f..30876451ee 100644
--- a/docs/usage/self-hosted-configuration.md
+++ b/docs/usage/self-hosted-configuration.md
@@ -172,6 +172,8 @@ By configuring using the environment it means that debug logging starts from the
 
 Additionally, if you configure `LOG_FORMAT=json` in env then logging will be done in JSON format instead of "pretty" format, which is usually better if you're doing any ingestion or parsing of the logs.
 
+Warning: Configuring `logLevel` config option or `--log-level` cli option is deprecated and will be removed in a major version.
+
 ## onboarding
 
 Set this to `false` if (a) you configure Renovate entirely on the bot side (i.e. empty `renovate.json` in repositories) and (b) you wish to run Renovate on every repository the bot has access to, and (c) you wish to skip the onboarding PRs.
diff --git a/docs/usage/self-hosting.md b/docs/usage/self-hosting.md
index 82c9cd183e..76218dd17c 100644
--- a/docs/usage/self-hosting.md
+++ b/docs/usage/self-hosting.md
@@ -101,7 +101,6 @@ metadata:
 data:
   config.json: |-
     {
-      "logLevel" : "debug",
       "repositories": ["orgname/repo","username/repo"],
       "dryRun" : "true"
     }
@@ -280,7 +279,6 @@ module.exports = {
   endpoint: 'https://self-hosted.gitlab/api/v4/',
   token: '**gitlab_token**',
   platform: 'gitlab',
-  logLevel: 'debug',
   onboardingConfig: {
     extends: ['config:base'],
   },
diff --git a/lib/config/config/__fixtures__/file.js b/lib/config/config/__fixtures__/file.js
index 61600196f1..e4fe0d8549 100644
--- a/lib/config/config/__fixtures__/file.js
+++ b/lib/config/config/__fixtures__/file.js
@@ -1,5 +1,4 @@
 // @ts-ignore
 module.exports = {
   token: 'abcdefg',
-  logLevel: 'error'
 };
diff --git a/lib/config/config/__fixtures__/with-force.js b/lib/config/config/__fixtures__/with-force.js
index d16cae37e4..ad2b1074fb 100644
--- a/lib/config/config/__fixtures__/with-force.js
+++ b/lib/config/config/__fixtures__/with-force.js
@@ -1,7 +1,6 @@
 // @ts-ignore
 module.exports = {
   token: 'abcdefg',
-  logLevel: 'error',
   force: {
     schedule: null,
   }
diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts
index b53af3cd45..deb1c21d4c 100644
--- a/lib/config/definitions.ts
+++ b/lib/config/definitions.ts
@@ -350,12 +350,10 @@ const options: RenovateOptions[] = [
   // Log options
   {
     name: 'logLevel',
-    description: 'Logging level',
+    description: 'Logging level. Deprecated, use `LOG_LEVEL` environment.',
     stage: 'global',
     type: 'string',
     allowedValues: ['fatal', 'error', 'warn', 'info', 'debug', 'trace'],
-    default: 'info',
-    env: 'LOG_LEVEL',
   },
   {
     name: 'logFile',
diff --git a/lib/config/file.spec.ts b/lib/config/file.spec.ts
index 4eeed34655..f5eb41da98 100644
--- a/lib/config/file.spec.ts
+++ b/lib/config/file.spec.ts
@@ -37,7 +37,6 @@ describe('config/file', () => {
         "platform": "github",
         "token":"abcdef",
         "logFileLevel": "warn",
-        "logLevel": "info",
         "onboarding": false,
         "gitAuthor": "Renovate Bot <renovate@whitesourcesoftware.com>"
         "onboardingConfig": {
diff --git a/lib/config/index.ts b/lib/config/index.ts
index 0f4699091c..8c8eae307a 100644
--- a/lib/config/index.ts
+++ b/lib/config/index.ts
@@ -80,8 +80,14 @@ export async function parseConfigs(
     delete config.privateKeyPath;
   }
 
-  // Set log level
-  levels('stdout', config.logLevel);
+  // Deprecated set log level: https://github.com/renovatebot/renovate/issues/8291
+  // istanbul ignore if
+  if (config.logLevel) {
+    logger.warn(
+      'Configuring logLevel in CLI or file is deprecated. Use LOG_LEVEL environment variable instead'
+    );
+    levels('stdout', config.logLevel);
+  }
 
   if (config.logContext) {
     // This only has an effect if logContext was defined via file or CLI, otherwise it would already have been detected in env
-- 
GitLab