Answers.Body: <p>If you disable <a href="https://craftcms.com/docs/3.x/config/config-settings.html#devmode" rel="nofollow noreferrer">devMode</a> in <code>config/general.php</code>, that information won't be logged.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-10T08:34:09.093Z
Answers.Text: devMode is turned off, but we're still at a minimum getting $_SERVER each time
Answers.UserDisplayName: owenmelbz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-14T03:15:27.467Z
Answers.LastActivityDate: 2020-08-14T03:15:27.467Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>Two links where I posted the result. Initially my own question:
  <a href="https://craftcms.stackexchange.com/a/37040/10980">https://craftcms.stackexchange.com/a/37040/10980</a>
  <a href="https://craftcms.stackexchange.com/questions/28213/is-it-possible-to-stop-craft-from-logging-so-much/37640#37640">Is it possible to stop Craft from logging so much?</a></p>
  <p>You need to configure app.php and set the variable <code>'logVars' =&gt; []</code> This removes all variables like $_SERVER, $_GET etc. from being logged.</p>
  <p>If you only want to remove the $_SERVER variables from being logged I recommend changing it for the existing Target classes that Craft uses for logging.
  This could be done as follows:</p>
  <pre><code>foreach(Craft::$app-&gt;getLog()-&gt;targets as $target) {
     $target-&gt;logVars = array_diff($target-&gt;logVars, ['_SERVER']);
  }
  </code></pre>
  <hr />
  <p>If you want to exclude classes which logs all mysql queries, you can also specify class exceptions. e.g.: <code>'except' =&gt; [ 'yii\db\Connection::*' ],</code></p>
  <p>In my case we redefined the whole log function for CraftCMS. Mainly it does :</p>
  <ul>
  <li>redirect output to php://stderr</li>
  <li>exclude certain classes from logging</li>
  <li>remove all variables like $_SERVER, $_GET</li>
  </ul>
  <p>The whole app.php with the above two configs looks as follows for me:</p>
  <pre><code>return [
      'modules' =&gt; [
          'mymodule' =&gt; MyModule::class,
          // My modules mapped here
      ],
      'components' =&gt; [
          'log' =&gt; function() {
              return Craft::createObject([
                  'class' =&gt; yii\log\Dispatcher::class,
                  'targets' =&gt; [
                      [
                          // You might not need class/url/levels property:
                          'class' =&gt; codemix\streamlog\Target::class,
                          'url' =&gt; 'php://stderr',
                          'levels' =&gt; Craft::$app-&gt;getConfig()-&gt;general-&gt;devMode ?
                              (yii\log\Logger::LEVEL_ERROR | yii\log\Logger::LEVEL_WARNING | yii\log\Logger::LEVEL_INFO) :
                              (yii\log\Logger::LEVEL_ERROR | yii\log\Logger::LEVEL_WARNING),
                          // Remove SQL Queries or any other class which logs:
                          'except' =&gt; [
                              'yii\base\View::renderFile',
                              'yii\db\Command::*',
                              'yii\db\Connection::*' // We don't want sql to be logged
                          ],
                          // don't log global variables like $_SERVER etc periodically in logs.
                          // See: yii\log\Target::class, collect method usually appends getContextMessage
                          'logVars' =&gt; []
                      ]
                  ]
              ]);
          }
      ],
      'bootstrap' =&gt; [
          // My module names here
      ],
  ];
  
  </code></pre>
  <p>Hope that helps.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-10T08:34:40.603Z
Answers.Text: devMode doesn't seem to turned off the extra $_SERVER we've got many sites all in production with devMode off and it still logs it out
Answers.UserDisplayName: owenmelbz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-10T09:56:37.227Z
Answers.Text: No I didn't mean to turn on devMode, just that you can easily do it no matter what you configured in devMode. Basically in your app.php you can add some configuration for loggers. In this configuration the main point is to specify `'logVars' => []` You can actually find the code in yii framework that logs those $_SERVER variables in yii\log\Target::class, the getContextMessage method. To see my example configuration of app.php which gives you an impression how it looks with comments see my second link in above answer.
Answers.UserDisplayName: judos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-10T10:02:43.053Z
Answers.Text: Updated my answer to be more specific, even so it's now the same as the links I posted.
Answers.UserDisplayName: judos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-10T13:19:56.300Z
Answers.Text: Hi, thanks for the more full example - however the problem I think we're having with the provided examples - they do "more" than we ideally want - We want 100% the exact defaults for Craft, but just with $_SERVER removed - from the example you've provided it would seem that it completely overwrites the defaults with a custom implementation? We don't know enough about the internals of Craft to know what we've changed and what knock on effects it will make. As far as you know is there anyway to simply "extend" or "merge" into the config rather than replacing it?
Answers.UserDisplayName: owenmelbz
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-01T09:58:36.803Z
Answers.Text: True. I adapted first half of my post to show you how you could modify existing Craft objects instead of redefining the Target class. Needs some testing though. But for all this I recommend you read the code yii2\log\Target and maybe subclasses you need in your case. As this class is really the origin where most of the logging logic happens.
Answers.UserDisplayName: judos
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-27T11:45:48.703Z
Answers.LastActivityDate: 2021-07-01T09:56:06.947Z
Answers.LastEditDate: 2021-07-01T09:56:06.947Z
Answers.UserDisplayName: judos
Body: <p>How can we disable Craft from logging MySQL queries and $_SERVER object into the logs?</p>
  <p>For our team, this creates additional noise that's not needed for us to debug issues.</p>
  <p>Thanks :)</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-13T20:26:05.123Z
Comments.Text: Sounds like you have ``devMode`` on?
Comments.UserDisplayName: RitterKnight
Tags: <error><logs>
Title: Remove $_SERVER and DB Queries from logs in 3.4+
ThreadText: # Remove $_SERVER and DB Queries from logs in 3.4+
  
  (Asked by: username_0 on 2020-08-13)
  
  How can we disable Craft from logging MySQL queries and $\_SERVER object into the logs?
  
  For our team, this creates additional noise that's not needed for us to debug issues.
  
  Thanks :)
  
  **Tags:** error, logs
  
  > **Comments:**
  > **username_1**: Sounds like you have ``devMode`` on?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-08-14. Score: 0
  
  If you disable [devMode](https://craftcms.com/docs/3.x/config/config-settings.html#devmode) in `config/general.php`, that information won't be logged.
  
  > **Comments:**
  > **username_0**: devMode is turned off, but we're still at a minimum getting $_SERVER each time  
  
  ---
  
  ### Answer by username_3 on 2021-04-27. Score: 0
  
  Two links where I posted the result. Initially my own question:
  <https://craftcms.stackexchange.com/a/37040/10980>
  [Is it possible to stop Craft from logging so much?](https://craftcms.stackexchange.com/questions/28213/is-it-possible-to-stop-craft-from-logging-so-much/37640#37640)
  
  You need to configure app.php and set the variable `'logVars' => []` This removes all variables like $\_SERVER, $\_GET etc. from being logged.
  
  If you only want to remove the $\_SERVER variables from being logged I recommend changing it for the existing Target classes that Craft uses for logging.
  This could be done as follows:
  
  ```
  foreach(Craft::$app->getLog()->targets as $target) {
     $target->logVars = array_diff($target->logVars, ['_SERVER']);
  }
  
  ```
  
  ---
  
  If you want to exclude classes which logs all mysql queries, you can also specify class exceptions. e.g.: `'except' => [ 'yii\db\Connection::*' ],`
  
  In my case we redefined the whole log function for CraftCMS. Mainly it does :
  
  * redirect output to php://stderr
  * exclude certain classes from logging
  * remove all variables like $\_SERVER, $\_GET
  
  The whole app.php with the above two configs looks as follows for me:
  
  ```
  return [
      'modules' => [
          'mymodule' => MyModule::class,
          // My modules mapped here
      ],
      'components' => [
          'log' => function() {
              return Craft::createObject([
                  'class' => yii\log\Dispatcher::class,
                  'targets' => [
                      [
                          // You might not need class/url/levels property:
                          'class' => codemix\streamlog\Target::class,
                          'url' => 'php://stderr',
                          'levels' => Craft::$app->getConfig()->general->devMode ?
                              (yii\log\Logger::LEVEL_ERROR | yii\log\Logger::LEVEL_WARNING | yii\log\Logger::LEVEL_INFO) :
                              (yii\log\Logger::LEVEL_ERROR | yii\log\Logger::LEVEL_WARNING),
                          // Remove SQL Queries or any other class which logs:
                          'except' => [
                              'yii\base\View::renderFile',
                              'yii\db\Command::*',
                              'yii\db\Connection::*' // We don't want sql to be logged
                          ],
                          // don't log global variables like $_SERVER etc periodically in logs.
                          // See: yii\log\Target::class, collect method usually appends getContextMessage
                          'logVars' => []
                      ]
                  ]
              ]);
          }
      ],
      'bootstrap' => [
          // My module names here
      ],
  ];
  
  ```
  
  Hope that helps.
  
  > **Comments:**
  > **username_0**: devMode doesn't seem to turned off the extra $_SERVER we've got many sites all in production with devMode off and it still logs it out  
  > **username_3**: No I didn't mean to turn on devMode, just that you can easily do it no matter what you configured in devMode. Basically in your app.php you can add some configuration for loggers. In this configuration the main point is to specify `'logVars' => []` You can actually find the code in yii framework that logs those $_SERVER variables in yii\log\Target::class, the getContextMessage method. To see my example configuration of app.php which gives you an impression how it looks with comments see my second link in above answer.  
  > **username_3**: Updated my answer to be more specific, even so it's now the same as the links I posted.  
  > **username_0**: Hi, thanks for the more full example - however the problem I think we're having with the provided examples - they do "more" than we ideally want - We want 100% the exact defaults for Craft, but just with $_SERVER removed - from the example you've provided it would seem that it completely overwrites the defaults with a custom implementation? We don't know enough about the internals of Craft to know what we've changed and what knock on effects it will make. As far as you know is there anyway to simply "extend" or "merge" into the config rather than replacing it?  
  > **username_3**: True. I adapted first half of my post to show you how you could modify existing Craft objects instead of redefining the Target class. Needs some testing though. But for all this I recommend you read the code yii2\log\Target and maybe subclasses you need in your case. As this class is really the origin where most of the logging logic happens.  
  
  ---
  
  