How to print a debug log?

前端 未结 15 1688
北海茫月
北海茫月 2020-12-12 10:07

I\'d like to debug some PHP code, but I guess printing a log to screen or file is fine for me.

How should I print a log in PHP code?

The u

相关标签:
15条回答
  • 2020-12-12 10:33

    I have used many of these, but since I usually need to debug when developing, and since I develop on localhost, I have followed the advice of others and now write to the browser's JavaScript debug console (see http://www.codeforest.net/debugging-php-in-browsers-javascript-console).

    That means that I can look at the web page which my PHP is generating in my browser & press F12 to quickly show/hide any debug trace.

    Since I am constantly looking at the developer tools for debugger, CSS layout, etc, it makes sense to look at my PHP loggon there.

    If anyone does decide to us that code, I made one minor change. After

    function debug($name, $var = null, $type = LOG) {

    I added

    $name = 'PHP: ' . $name;

    This is because my server side PHP generates HTML conatining JavaScript & I find it useful to distinguish between output from PHP & JS.

    (Note: I am currently updating this to allow me to switch on & off different output types: from PHP, from JS, and database access)

    0 讨论(0)
  • 2020-12-12 10:37

    You can use:

    <?php
    echo '<script>console.log("debug log")</script>';
    ?>
    
    0 讨论(0)
  • 2020-12-12 10:38

    I use cakephp so I use:

    $this->log(YOUR_STRING_GOES_HERE, 'debug');
    
    0 讨论(0)
提交回复
热议问题