Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] Fix array to string conversion in errorlog writer #35821

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/private/Log/Errorlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@

namespace OC\Log;

use OC\SystemConfig;
use OCP\Log\IWriter;

class Errorlog implements IWriter {
class Errorlog extends LogDetails implements IWriter {

/** @var string */
protected $tag;

public function __construct(string $tag = 'owncloud') {
public function __construct(SystemConfig $config, string $tag = 'owncloud') {
parent::__construct($config);
$this->tag = $tag;
}

/**
* write a message in the log
* Write a message in the log
*
* @param string $app
* @param string $message
* @param string|array $message
* @param int $level
*/
public function write(string $app, $message, int $level) {
error_log('[' . $this->tag . ']['.$app.']['.$level.'] '.$message);
error_log('[' . $this->tag . ']['.$app.']['.$level.'] '.$this->logDetailsAsJSON($app, $message, $level));
}
}
4 changes: 2 additions & 2 deletions lib/private/Log/LogFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(IServerContainer $c, SystemConfig $systemConfig) {
public function get(string $type):IWriter {
switch (strtolower($type)) {
case 'errorlog':
return new Errorlog();
return new Errorlog($this->systemConfig);
case 'syslog':
return $this->c->resolve(Syslog::class);
case 'systemd':
Expand All @@ -73,7 +73,7 @@ public function getCustomLogger(string $path):ILogger {
protected function createNewLogger(string $type, string $tag, string $path): IWriter {
switch (strtolower($type)) {
case 'errorlog':
return new Errorlog($tag);
return new Errorlog($this->systemConfig, $tag);
case 'syslog':
return new Syslog($this->systemConfig, $tag);
case 'systemd':
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Log/Syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __destruct() {
/**
* write a message in the log
* @param string $app
* @param string $message
* @param string|array $message
* @param int $level
*/
public function write(string $app, $message, int $level) {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Log/Systemdlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(SystemConfig $config, ?string $tag = null) {
/**
* Write a message to the log.
* @param string $app
* @param string $message
* @param string|array $message
* @param int $level
*/
public function write(string $app, $message, int $level) {
Expand Down
4 changes: 4 additions & 0 deletions lib/public/Log/IWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
interface IWriter {
/**
* @since 14.0.0
*
* @param string $app
* @param string|array $message
* @param int $level
*/
public function write(string $app, $message, int $level);
}