Manual:Structured logging/ja

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

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

からロガーを取得
Where  should be the name of an extension (or prefixed with the name) or one of the core logging channels.

深刻度レベル情報の利用

 * ローカルの開発には便利でも、製品版ウィキに出力するには一般的に「スパムに近似」するメッセージです. 一般的に現状でwfDebugを利用してログ記録したものを網羅します.
 * ローカルの開発には便利でも、製品版ウィキに出力するには一般的に「スパムに近似」するメッセージです. 一般的に現状で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. コールを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. コールを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.

PSR-3標準に含まれる深刻度レベルは他にもありますが、MediaWikiでの使用は非推奨です.

ログ記録コンテクストに構造化データを付加する
ログ方式に関わらず、どれも次のようなオプションでコンテクスト・オブジェクトがあります.

他の利用者が関連メッセージの検索やエラーの原因遡求に使えるように、ログメッセージのコンテクスト・オブジェクトには有用な構造化データを付加する必要があります. 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