Yii2 dumps '_GET'
, '_POST'
, '_FILES'
, '_COOKIE'
, '_SESSION'
, '_SERVER'
PHP variables to the logs after each request:
2019-05-22 06:24:44 [-][-][-][info][application] $_GET = []
$_POST = []
$_FILES = []
$_COOKIE = []
$_SERVER = [
'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0'
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
'HTTP_ACCEPT_LANGUAGE' => 'en-ZA,en-GB;q=0.8,en-US;q=0.5,en;q=0.3'
'HTTP_ACCEPT_ENCODING' => 'gzip, deflate'
'HTTP_DNT' => '1'
'HTTP_CONNECTION' => 'keep-alive'
'HTTP_UPGRADE_INSECURE_REQUESTS' => '1'
'HTTP_CACHE_CONTROL' => 'max-age=0'
'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin'
'
'SERVER_SOFTWARE' => 'Apache/2.4.38 (Ubuntu)'
...
]
Urgh!
Let's remove them from our logs. Update your config/app.php
to include the log
component:
FileTarget
is the default log target used by Craft. If we want to keep the log output in default location, we need to specify the other log options:
class
- The log targetlevels
- A bitmap of all required log levelslogFile
- An aliased path to your log file
To limit which PHP variables are logged, set logVars
to ['_GET', '_POST']
or any subset of the variables you like.
Now when you tail your logs, they aren't polluted with extraneous data.