简体   繁体   English

使用ChromeLogger和ChromePHP从php函数内部登录

[英]Log from inside php functions using ChromeLogger and ChromePHP

I'm making a foray into php (wordpress) and have set up ChromeLogger ( http://craig.is/writing/chrome-logger ) and ChromePHP ( https://github.com/ccampbell/chromephp ). 我正在尝试使用php(wordpress),并设置了ChromeLogger( http://craig.is/writing/chrome-logger )和ChromePHP( https://github.com/ccampbell/chromephp )。

I can now log ok from my templates, but i'd really like to be able to log to the console from inside php functions too (like in js), which is very useful for debugging. 现在,我可以从模板登录了,但是我真的很想能够从php函数内部(例如js)登录控制台,这对于调试非常有用。 In this case my function is in 在这种情况下,我的功能是

mywordpressfolder/wp-content/themes/mytheme/functions.php

Like i say i'm new to php and am not sure how it all fits together with the browser and whether this is possible. 就像我说的,我是php的新手,不确定如何将其与浏览器配合使用以及是否可行。 Is it? 是吗? If so, how? 如果是这样,怎么办?

thanks, max 谢谢,最大

I realised that i don't need to see debug output in the browser console, particularly, (ie i just need to see it) and that displaying it to the browser console might be impossible anyway in this case. 我意识到我不需要在浏览器控制台中看到调试输出,尤其是(即,我只需要查看它),在这种情况下,无论如何都不可能将其显示在浏览器控制台中。 So i wrote a helper function which writes out the filename and line number of the caller, along with a passed string argument. 因此,我编写了一个辅助函数,该函数写出调用方的文件名和行号以及传递的字符串参数。

function ldb($string){
  $caller = array_shift(debug_backtrace());  
  error_log('### ' .$caller['file'] . ":" . $caller['line'] . " : " . $string . "\n", 3, "/tmp/wordpress.log");
}

I believe the standard php logging location is /var/tmp but i'm just writing into /tmp here. 我相信标准的php日志记录位置是/ var / tmp,但我只是在这里写入/ tmp。 Produces output like this: 产生如下输出:

### /home/max/work/wordpress/wp-content/themes/viptheme/functions.php:1098 : auth worked but couldn't match an account on non-wp site
### /home/max/work/wordpress/wp-content/themes/viptheme/functions.php:1036 : external auth successful

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM