私は現在、私たちのプロジェクトの1つで、独自のロギングソリューションからlog4phpに移行する過程にあります。私たち自身のソリューションには、以下に投稿したヘルパーメソッドがあります。このメソッドの目的は、変数の内容(およびそのメンバーのいずれかを再帰的に)をログに書き込むことです。
log4phpでのこのメソッドの同等の場所は、Loggerクラスです(私は推測します)。しかし、機能を統合するための適切な方法は何でしょうか。
Loggerから派生して拡張する必要がありますか?または、この機能を「プラグイン」する方法はありますか。
前もって感謝します。
/**
* Dump the complete content of the target object to the log.
*
* @param mixed $target The object to dump.
* @param int $level The verbosity level.
* @param int $indent Indentation level.
*/
public static function dump( $target, $level = Logging::eDEBUG, $indent = 0 ) {
if( $level < self::getInstance()->logLevel ) return;
if( null == $target ) {
self::log( "d", "> " . str_repeat( "\t", $indent ) . "null", $level );
return;
}
if( is_string( $target ) || is_numeric( $target ) ) {
self::log( "d", "> " . str_repeat( "\t", $indent ) . $target, $level );
return;
}
foreach( $target as $key => $value ) {
if( is_array( $value ) ) {
self::log( "d", "> " . str_repeat( "\t", $indent ) . $key . " -> Array (", $level );
self::dump( $value, $level, $indent + 1 );
self::log( "d", "> " . str_repeat( "\t", $indent ) . ")", $level );
continue;
}
if( is_object( $value ) ) {
self::log( "d", "> " . str_repeat( "\t", $indent ) . $key . " -> Object (", $level );
self::dump( (array)$value, $level, $indent + 1 );
self::log( "d", "> " . str_repeat( "\t", $indent ) . ")", $level );
} else {
self::log( "d", "> " . str_repeat( "\t", $indent ) . $key . " -> " . $value, $level );
}
}
}