debug: Add cli_argv field to monolog WikiProcessor
authorTimo Tijhof <krinklemail@gmail.com>
Fri, 18 Aug 2017 23:47:35 +0000 (16:47 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 18 Aug 2017 23:47:35 +0000 (16:47 -0700)
Follows investigation from T172559, where we found that there is no explicit
way to find what script triggered particular error messages when the script
was run from the command-line (as opposed to a web request, where the
built-in WebProcessor adds fields like http_method and url).

Change-Id: Ia9641274a164137dcc30324578d750cc662976ee

includes/debug/logger/monolog/WikiProcessor.php

index 5e32887..e39a2c3 100644 (file)
@@ -35,15 +35,13 @@ class WikiProcessor {
         */
        public function __invoke( array $record ) {
                global $wgVersion;
-               $record['extra'] = array_merge(
-                       $record['extra'],
-                       [
-                               'host' => wfHostname(),
-                               'wiki' => wfWikiID(),
-                               'mwversion' => $wgVersion,
-                               'reqId' => \WebRequest::getRequestId(),
-                       ]
-               );
+               $record['extra']['host'] = wfHostname();
+               $record['extra']['wiki'] = wfWikiID();
+               $record['extra']['mwversion'] = $wgVersion;
+               $record['extra']['reqId'] = \WebRequest::getRequestId();
+               if ( PHP_SAPI === 'cli' && isset( $_SERVER['argv'] ) ) {
+                       $record['extra']['cli_argv'] = implode( ' ', $_SERVER['argv'] );
+               }
                return $record;
        }