filebackend: Convert trigger_error to PSR log warning
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 26 Sep 2019 00:57:01 +0000 (01:57 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Thu, 26 Sep 2019 00:59:21 +0000 (01:59 +0100)
* Add 'filebackend' name to the context.
* Convert message to a normalized form for better de-duplication
  in Logstash so that it is easier to see whether something is rare
  or common. Without this, each instance is unique and it might seem
  rare in a small sample of log messages.

This does not fully solve T231107, because we'd really want to
know at least the file name the issue is about, but it seems
the FileBackendStore does not have access to that right now,
that's for a future commit. (It also can't be logged from the
caller right now because this method does not expose the result
of the operation in question).

Bug: T231107
Change-Id: Iaf18d7d5c11334c84077667aa147d99fadb76a30

includes/libs/filebackend/FileBackendStore.php

index d7d428e..ffb8793 100644 (file)
@@ -1440,7 +1440,10 @@ abstract class FileBackendStore extends FileBackend {
                                $name = strtolower( $name );
                                $maxHVLen = in_array( $name, $longs ) ? INF : 255;
                                if ( strlen( $name ) > 255 || strlen( $value ) > $maxHVLen ) {
-                                       trigger_error( "Header '$name: $value' is too long." );
+                                       $this->logger->error( "Header '{header}' is too long.", [
+                                               'filebackend' => $this->name,
+                                               'header' => "$name: $value",
+                                       ] );
                                } else {
                                        $newHeaders[$name] = strlen( $value ) ? $value : ''; // null/false => ""
                                }
@@ -1789,7 +1792,9 @@ abstract class FileBackendStore extends FileBackend {
         */
        final protected function deleteContainerCache( $container ) {
                if ( !$this->memCache->delete( $this->containerCacheKey( $container ), 300 ) ) {
-                       trigger_error( "Unable to delete stat cache for container $container." );
+                       $this->logger->warning( "Unable to delete stat cache for container {container}.",
+                               [ 'filebackend' => $this->name, 'container' => $container ]
+                       );
                }
        }
 
@@ -1887,7 +1892,9 @@ abstract class FileBackendStore extends FileBackend {
                        return; // invalid storage path
                }
                if ( !$this->memCache->delete( $this->fileCacheKey( $path ), 300 ) ) {
-                       trigger_error( "Unable to delete stat cache for file $path." );
+                       $this->logger->warning( "Unable to delete stat cache for file {path}.",
+                               [ 'filebackend' => $this->name, 'path' => $path ]
+                       );
                }
        }