diff options
author | Gergő Tisza <tgr.huwiki@gmail.com> | 2017-10-23 01:29:20 -0700 |
---|---|---|
committer | Gergő Tisza <tgr.huwiki@gmail.com> | 2017-10-26 21:06:03 -0700 |
commit | 7d9dbc0040034e1dbe97c959d37d96c8ca400aa5 (patch) | |
tree | b3399cfd2a713a3cd4a3169e03b285701c726747 /includes/shell | |
parent | fdb3f0d08a1f67231e8ea1a0abb8e42bfdf0f457 (diff) | |
download | mediawikicore-7d9dbc0040034e1dbe97c959d37d96c8ca400aa5.tar.gz mediawikicore-7d9dbc0040034e1dbe97c959d37d96c8ca400aa5.zip |
MediaWiki\Shell: log stderr
Change-Id: I1495fe2aba10102d7e36c3a3e5fdabf97f14546b
Diffstat (limited to 'includes/shell')
-rw-r--r-- | includes/shell/Command.php | 32 | ||||
-rw-r--r-- | includes/shell/CommandFactory.php | 16 |
2 files changed, 43 insertions, 5 deletions
diff --git a/includes/shell/Command.php b/includes/shell/Command.php index 1816c5aed175..9f080d51411d 100644 --- a/includes/shell/Command.php +++ b/includes/shell/Command.php @@ -57,7 +57,10 @@ class Command { private $method; /** @var bool */ - private $useStderr = false; + private $doIncludeStderr = false; + + /** @var bool */ + private $doLogStderr = false; /** @var bool */ private $everExecuted = false; @@ -180,7 +183,19 @@ class Command { * @return $this */ public function includeStderr( $yesno = true ) { - $this->useStderr = $yesno; + $this->doIncludeStderr = $yesno; + + return $this; + } + + /** + * When enabled, text sent to stderr will be logged with a level of 'error'. + * + * @param bool $yesno + * @return $this + */ + public function logStderr( $yesno = true ) { + $this->doLogStderr = $yesno; return $this; } @@ -235,7 +250,7 @@ class Command { $cmd = '/bin/bash ' . escapeshellarg( __DIR__ . '/limit.sh' ) . ' ' . escapeshellarg( $cmd ) . ' ' . escapeshellarg( - "MW_INCLUDE_STDERR=" . ( $this->useStderr ? '1' : '' ) . ';' . + "MW_INCLUDE_STDERR=" . ( $this->doIncludeStderr ? '1' : '' ) . ';' . "MW_CPU_LIMIT=$time; " . 'MW_CGROUP=' . escapeshellarg( $this->cgroup ) . '; ' . "MW_MEM_LIMIT=$mem; " . @@ -246,7 +261,7 @@ class Command { $useLogPipe = true; } } - if ( !$useLogPipe && $this->useStderr ) { + if ( !$useLogPipe && $this->doIncludeStderr ) { $cmd .= ' 2>&1'; } @@ -424,6 +439,15 @@ class Command { $this->logger->warning( "$logMsg: {command}", [ 'command' => $cmd ] ); } + if ( $errBuffer && $this->doLogStderr ) { + $this->logger->error( "Error running {command}: {error}", [ + 'command' => $cmd, + 'error' => $errBuffer, + 'exitcode' => $retval, + 'exception' => new Exception( 'Shell error' ), + ] ); + } + return new Result( $retval, $outBuffer, $errBuffer ); } } diff --git a/includes/shell/CommandFactory.php b/includes/shell/CommandFactory.php index c0b8f899ed2e..84dd50f71fbb 100644 --- a/includes/shell/CommandFactory.php +++ b/includes/shell/CommandFactory.php @@ -37,6 +37,9 @@ class CommandFactory { /** @var string|bool */ private $cgroup; + /** @var bool */ + private $doLogStderr = false; + /** * Constructor * @@ -50,6 +53,16 @@ class CommandFactory { } /** + * When enabled, text sent to stderr will be logged with a level of 'error'. + * + * @param bool $yesno + * @see Command::logStderr + */ + public function logStderr( $yesno = true ) { + $this->doLogStderr = $yesno; + } + + /** * Instantiates a new Command * * @return Command @@ -60,6 +73,7 @@ class CommandFactory { return $command ->limits( $this->limits ) - ->cgroup( $this->cgroup ); + ->cgroup( $this->cgroup ) + ->logStderr( $this->doLogStderr ); } } |