[GH-ISSUE #150] FirePHPHandler Log arrays as Firephp "table" #48

Closed
opened 2026-03-04 02:11:39 +03:00 by kerem · 7 comments
Owner

Originally created by @Surt on GitHub (Jan 18, 2013).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/150

Hi,

Firephp has a good way to render "tables" http://www.firephp.org/HQ/Use.htm
I was triying to figure how to send arrays to a debug message and make it appear as the firephp "table" format. But I ended at line 191 on Logger.php 'message' => (string) $message,.
All records are cast to strings? How can I send different types of variables?

Originally created by @Surt on GitHub (Jan 18, 2013). Original GitHub issue: https://github.com/Seldaek/monolog/issues/150 Hi, Firephp has a good way to render "tables" http://www.firephp.org/HQ/Use.htm I was triying to figure how to send arrays to a debug message and make it appear as the firephp "table" format. But I ended at line 191 on Logger.php `'message' => (string) $message,`. All records are cast to strings? How can I send different types of variables?
kerem closed this issue 2026-03-04 02:11:40 +03:00
Author
Owner

@stof commented on GitHub (Jan 18, 2013):

The monolog API is addRecord(integer|string $level, string $message, array $context). If you want include an array (or an object) in the log record, put it inside the context. You will then see it in Firephp

<!-- gh-comment-id:12441225 --> @stof commented on GitHub (Jan 18, 2013): The monolog API is `addRecord(integer|string $level, string $message, array $context)`. If you want include an array (or an object) in the log record, put it inside the context. You will then see it in Firephp
Author
Owner

@Surt commented on GitHub (Jan 19, 2013):

Ouch! Thank you and sorry, it was there and I didn't saw it
Finally I managed to create a "dirty" workaround overwriting handle in FirePHPHandler.
It's not so beautiful, but I just use it on developing, so, no performance issues.

    /**
     * {@inheritdoc}
     */
    public function handle(array $record)
    {
        if ($record['level'] < $this->level) {
            return false;
        }

        if(isset($record['context']['table'])){
            require_once('Path/to/FirePHP.php');
            fb($record['context']['table'], $record['message'], 'TABLE');
        }
        else {
            return parent::handle($record);
        }
    }

using it this way

$log->debug("Benchmark", array('table'=>array(....)));
<!-- gh-comment-id:12454464 --> @Surt commented on GitHub (Jan 19, 2013): Ouch! Thank you and sorry, it was there and I didn't saw it Finally I managed to create a "dirty" workaround overwriting handle in FirePHPHandler. It's not so beautiful, but I just use it on developing, so, no performance issues. ``` /** * {@inheritdoc} */ public function handle(array $record) { if ($record['level'] < $this->level) { return false; } if(isset($record['context']['table'])){ require_once('Path/to/FirePHP.php'); fb($record['context']['table'], $record['message'], 'TABLE'); } else { return parent::handle($record); } } ``` using it this way ``` $log->debug("Benchmark", array('table'=>array(....))); ```
Author
Owner

@Seldaek commented on GitHub (Jan 19, 2013):

@Surt if you think this could be of some value in the core handler I'm not particularly against it, but I don't really use firephp so I am not sure. It seems to me like it's hard to say when something should be a table and when not. I mean it's context dependent, which is hard to solve in an abstraction.

<!-- gh-comment-id:12459036 --> @Seldaek commented on GitHub (Jan 19, 2013): @Surt if you think this could be of some value in the core handler I'm not particularly against it, but I don't really use firephp so I am not sure. It seems to me like it's hard to say when something should be a table and when not. I mean it's context dependent, which is hard to solve in an abstraction.
Author
Owner

@Surt commented on GitHub (Jan 19, 2013):

Umm I'm not sure, I think that is not a good addition since it breaks a little the uniformity (don't know about other handlers).
Anyway, the issue could stay here for everyone looking for a workaround.
Anyone can drop a comment if they find the post useful.

I use the tables in this way:
Screenshot_1

by the way ;) Seldaek I can't stop using your Dwoo library. No one makes me feel like it :)

<!-- gh-comment-id:12459413 --> @Surt commented on GitHub (Jan 19, 2013): Umm I'm not sure, I think that is not a good addition since it breaks a little the uniformity (don't know about other handlers). Anyway, the issue could stay here for everyone looking for a workaround. Anyone can drop a comment if they find the post useful. I use the tables in this way: ![Screenshot_1](https://f.cloud.github.com/assets/48085/80549/ee3c2264-626c-11e2-8445-de752c46a4ad.png) by the way ;) Seldaek I can't stop using your Dwoo library. No one makes me feel like it :)
Author
Owner

@Seldaek commented on GitHub (Jan 19, 2013):

@Surt eh well, glad to hear but I would really recommend using twig just because dwoo is not going to receive much maintenance ever I'm afraid. And by now twig can do pretty much everything dwoo could besides the automatic php function mapping, but that is in a way for the best in terms of enforcing best practices.

<!-- gh-comment-id:12459781 --> @Seldaek commented on GitHub (Jan 19, 2013): @Surt eh well, glad to hear but I would really recommend using twig just because dwoo is not going to receive much maintenance ever I'm afraid. And by now twig can do pretty much everything dwoo could besides the automatic php function mapping, but that is in a way for the best in terms of enforcing best practices.
Author
Owner

@stof commented on GitHub (Jan 19, 2013):

@Seldaek Twig also has a way to map php functions to Twig functions automatically (but not documented and not recommended)

<!-- gh-comment-id:12460782 --> @stof commented on GitHub (Jan 19, 2013): @Seldaek Twig also has a way to map php functions to Twig functions automatically (but not documented and not recommended)
Author
Owner

@Surt commented on GitHub (Jan 19, 2013):

:) I know about Twig, I'm triying to use it but i don't like the syntax and need to rewrite my "plugins" again :(

About the post topic, my last contribution break the headers and nothing except tables appear on the logs, due to the Firephp core code.... so I manage to read the FirePHP Wildfire Wiki and ended with this on the "format" method of WildfireFormatter.php

        if(isset($record['context']['table'])){
            $type  = 'TABLE';
            $label = $record['message'];
            $message = $record['context']['table'];
        }
        else {
            $type  = $this->logLevels[$record['level']];
            $label = $record['channel'];
        }

        // Create JSON object describing the appearance of the message in the console
        $json = $this->toJson(array(
            array(
                'Type'  => $type,
                'File'  => $file,
                'Line'  => $line,
                'Label' => $label,
            ),
            $message
        ), $handleError);

as always, using it this way, so I can render tables at any level
$log->debug("Benchmark", array('table'=>array(....)));

The table array must be non-associative.

This code is better since it lives in the formatter and does not use the FirePHP library in any way (there was no need to use it anyway thanks to your great work)

<!-- gh-comment-id:12460948 --> @Surt commented on GitHub (Jan 19, 2013): :) I know about Twig, I'm triying to use it but i don't like the syntax and need to rewrite my "plugins" again :( About the post topic, my last contribution break the headers and nothing except tables appear on the logs, due to the Firephp core code.... so I manage to read the FirePHP Wildfire Wiki and ended with this on the "format" method of WildfireFormatter.php ``` if(isset($record['context']['table'])){ $type = 'TABLE'; $label = $record['message']; $message = $record['context']['table']; } else { $type = $this->logLevels[$record['level']]; $label = $record['channel']; } // Create JSON object describing the appearance of the message in the console $json = $this->toJson(array( array( 'Type' => $type, 'File' => $file, 'Line' => $line, 'Label' => $label, ), $message ), $handleError); ``` as always, using it this way, so I can render tables at any level `$log->debug("Benchmark", array('table'=>array(....)));` The table array must be non-associative. This code is better since it lives in the formatter and does not use the FirePHP library in any way (there was no need to use it anyway thanks to your great work)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#48
No description provided.