always require a message paramter for data logging
also ensure it plays well with current log reader Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
46aaeb4561
commit
e008444887
|
@ -33,7 +33,7 @@ class LogContext {
|
||||||
protected $details;
|
protected $details;
|
||||||
|
|
||||||
public function setDescription(string $description): LogContext {
|
public function setDescription(string $description): LogContext {
|
||||||
$this->details['description'] = $description;
|
$this->details['message'] = $description;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,8 +162,10 @@ class Logger {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$details = $logContext->getDetails();
|
||||||
$this->flowLogger->logData(
|
$this->flowLogger->logData(
|
||||||
$logContext->getDetails(),
|
$details['message'],
|
||||||
|
$details,
|
||||||
['app' => Application::APP_ID, 'level' => $context['level']]
|
['app' => Application::APP_ID, 'level' => $context['level']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,7 +340,7 @@ class Log implements ILogger, IDataLogger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logData(array $data, array $context = []): void {
|
public function logData(string $message, array $data, array $context = []): void {
|
||||||
$app = $context['app'] ?? 'no app in context';
|
$app = $context['app'] ?? 'no app in context';
|
||||||
$level = $context['level'] ?? ILogger::ERROR;
|
$level = $context['level'] ?? ILogger::ERROR;
|
||||||
|
|
||||||
|
@ -350,6 +350,7 @@ class Log implements ILogger, IDataLogger {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($level >= $minLevel) {
|
if ($level >= $minLevel) {
|
||||||
|
$data['message'] = $message;
|
||||||
if (!$this->logger instanceof IFileBased) {
|
if (!$this->logger instanceof IFileBased) {
|
||||||
$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
|
$data = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_UNESCAPED_SLASHES);
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,16 @@ abstract class LogDetails {
|
||||||
'userAgent',
|
'userAgent',
|
||||||
'version'
|
'version'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(is_array($message) && !array_key_exists('Exception', $message)) {
|
||||||
|
// Exception messages should stay as they are,
|
||||||
|
// anything else modern is split to 'message' (string) and
|
||||||
|
// data (array) fields
|
||||||
|
$shortMessage = $message['message'] ?? '(no message provided)';
|
||||||
|
$entry['data'] = $message;
|
||||||
|
$entry['message'] = $shortMessage;
|
||||||
|
}
|
||||||
|
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,15 @@ namespace OCP\Log;
|
||||||
* Interface IDataLogger
|
* Interface IDataLogger
|
||||||
*
|
*
|
||||||
* @package OCP\Log
|
* @package OCP\Log
|
||||||
* @since 18.0.0
|
* @since 18.0.1
|
||||||
*/
|
*/
|
||||||
interface IDataLogger {
|
interface IDataLogger {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* allows to log custom data, similar to how logException works
|
* allows to log custom data, similar to how logException works
|
||||||
*
|
*
|
||||||
* @since 18.0.0
|
* @since 18.0.1
|
||||||
*/
|
*/
|
||||||
public function logData(array $data, array $context = []): void;
|
public function logData(string $message, array $data, array $context = []): void;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue