Manual:Structured logging/ja

ログ記録の構造化とは運用上の（バグ修正用）ログ記録で、ポストプロセスに役立つ構造化データで構成されています. （Special:Logへのログ記録）と混同しないでください.

MediaWiki 1.25以降、MediaWikiコアと拡張機能ではPSR-3ログ標準を採用し、バグ修正コールの 及び は廃止されました. PSR-3 標準はログメッセージ単位で一連のコンテクストデータを添付できるため、構造化されたキー値のペアが利用できます.

Get a logger from the
Where  should be the name of an extension (or prefixed with the name) or one of the core logging channels.

Use informative severity levels

 * These are messages that are useful for local development and are generally too "spammy" to output on a production wiki. This would typically include anything currently being logged via wfDebug.
 * These are messages that are useful for local development and are generally too "spammy" to output on a production wiki. This would typically include anything currently being logged via wfDebug.


 * Valuable state change information. This level is a great place to record information that would be useful in a production environment when tracing the path of a request that eventually had an error. This is currently the level automatically associated with  calls when mapped to PSR-3.
 * Valuable state change information. This level is a great place to record information that would be useful in a production environment when tracing the path of a request that eventually had an error. This is currently the level automatically associated with  calls when mapped to PSR-3.


 * A soft error condition such as a recoverable error or another condition that typically should not be seen but isn't halting for the operation in process.
 * A soft error condition such as a recoverable error or another condition that typically should not be seen but isn't halting for the operation in process.


 * A hard error such as a caught exception with no recovery path.
 * A hard error such as a caught exception with no recovery path.

The PSR-3 standard includes other severity levels, however they are not recommended for usage in MediaWiki.

Add structured data to logging context
All the logging methods take an optional context object, for example:

You should add useful structured information to your log messages in this context object that others can be use to find related messages and trace the cause of the error. This is especially important and useful for  and   level messages where the wiki operator may not be familiar with the code path and needs to be able to file a good bug report.


 * If you pass an Exception object in the context parameter, it MUST be in the 'exception' key (e.g. )
 * Record the method that emitted the error:
 * Attach parameters or other interesting state to messages. You can use objects or any other type; they will be converted to strings in a reasonable manner (e.g. using the  magic method if it exists).
 * Standard parameters (wiki name, server name etc) will be added automatically. Details depend on what logging service you use, but you'll probably end up using.
 * Replace faux structure such as tab-separated items, label=value/label:value pairs, or json serialization.
 * Record stack traces by creating an exception object, adding it to the log context and then discarding it.

Many log aggregators try to deduplicate logs by message, so try to keep mutable details out of the message and move them into the context. The logger will replace any tokens inside curly braces with the corresponding value from the context. For example, the code

will result in something like

For maximum compatibility with various logging backends, do not use these keys in your context data:



Configuring your wiki for structured logging
For backwards compatibility, if you are using the default MediaWiki configuration and have configured basic logging, then whether you supply a context object to these logger methods or to MediaWiki's global functions such as, the information in the context object does not appear in the log files you've configured. You should implement a better logger, such as monolog, as the logger "service provider interface". および を参照してください.

関連項目

 * Requests for comment/Structured logging
 * PSR-3 logging standard
 * logstash - Wikimedia feeds most of its MediaWiki logs into logstash, which understands the structured logging
 * logstash - Wikimedia feeds most of its MediaWiki logs into logstash, which understands the structured logging