Php “我如何实施?”;“物体倾倒”;用log4hp?
在我们的一个项目中,我目前正在从我们自己的专有日志解决方案转向Log4HP。我们自己的解决方案有一个助手方法,我在下面发布了这个方法。该方法的目的是将变量(及其任何成员)的内容递归地写入日志 log4ppp中此方法的等效位置是Logger类(我假设)。但是我想知道集成这些功能的正确方法是什么 我应该从Logger派生并扩展它吗?或者有没有办法“插入”此功能 提前谢谢Php “我如何实施?”;“物体倾倒”;用log4hp?,php,logging,log4php,Php,Logging,Log4php,在我们的一个项目中,我目前正在从我们自己的专有日志解决方案转向Log4HP。我们自己的解决方案有一个助手方法,我在下面发布了这个方法。该方法的目的是将变量(及其任何成员)的内容递归地写入日志 log4ppp中此方法的等效位置是Logger类(我假设)。但是我想知道集成这些功能的正确方法是什么 我应该从Logger派生并扩展它吗?或者有没有办法“插入”此功能 提前谢谢 /** * Dump the complete content of the target object to the log.
/**
* 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 );
}
}
}
/**
*将目标对象的完整内容转储到日志中。
*
*@param mixed$target要转储的对象。
*@param int$level详细级别。
*@param int$缩进缩进级别。
*/
公共静态函数转储($target,$level=Logging::eDEBUG,$indent=0){
if($levellogLevel)返回;
如果(空==$target){
self::log(“d”,“>”.str_repeat(“\t”,$indent)。“null”,$level);
返回;
}
如果(是字符串($target)|是数字($target)){
self::log(“d”,“>”.str_repeat(“\t”,$indent)。$target,$level);
返回;
}
foreach($key=>$value作为目标){
if(是_数组($value)){
self::log(“d”,“>”.str\u repeat(“\t”,$indent)。$key.->Array(“,$level”);
self::dump($value、$level、$indent+1);
self::log(“d”,“>”.str_repeat(“\t”,$indent)。”,$level);
继续;
}
如果(是对象($value)){
self::log(“d”,“>”.str\u repeat(“\t”,$indent)。$key.->Object(“,$level”);
self::dump((数组)$value、$level、$indent+1);
self::log(“d”,“>”.str_repeat(“\t”,$indent)。”,$level);
}否则{
self::log(“d”,“>”.str_repeat(“\t”,$indent)。$key.->“$value,$level);
}
}
}
这些都在中解释。为什么不使用打印()
?您也可以使用var\u export()看起来我一定跳过了这一部分。我不知道log4ppp已经隐式地执行了这个任务。谢谢