[GH-ISSUE #56] ChromePHP Handler #15

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

Originally created by @bdvir on GitHub (Feb 19, 2012).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/56

Feature request.

Do you have any plans implementing http://www.chromephp.com/ handler?

Originally created by @bdvir on GitHub (Feb 19, 2012). Original GitHub issue: https://github.com/Seldaek/monolog/issues/56 Feature request. Do you have any plans implementing http://www.chromephp.com/ handler?
kerem closed this issue 2026-03-04 02:11:21 +03:00
Author
Owner

@stof commented on GitHub (Feb 19, 2012):

This look interesting.

@ccampbell do you have a place where you describe the way the headers should be formatted to send a log message to the extension ?

<!-- gh-comment-id:4044716 --> @stof commented on GitHub (Feb 19, 2012): This look interesting. @ccampbell do you have a place where you describe the way the headers should be formatted to send a log message to the extension ?
Author
Owner

@ccampbell commented on GitHub (Feb 19, 2012):

I don't have it documented anywhere, but I can give a brief overview.

The data to be logged starts out with an array that looks like this:

ChromePHP Array

Each log is an array entry in rows that looks like this:

$data = array(
    0 => 'log label', // if applicable
    1 => 'log message', // or array / array representation of object
    2 => 'path/to/file.php : line_number',
    3 => '' // log type ('log', 'error', 'warn', etc)
);

Then you would convert this data to a header by doing something like this:

header('X-ChromePhp-Data: ' . base64_encode(utf8_encode(json_encode($data))));

Check out the source at: https://github.com/ccampbell/chromephp/blob/master/ChromePhp.php to see exactly what is going on.

<!-- gh-comment-id:4044944 --> @ccampbell commented on GitHub (Feb 19, 2012): I don't have it documented anywhere, but I can give a brief overview. The data to be logged starts out with an array that looks like this: ![ChromePHP Array](http://f.cl.ly/items/1A3c281k3M2p3r1a1O1E/Screen%20shot%202012-02-19%20at%203.24.00%20PM.png) Each log is an array entry in rows that looks like this: ``` php $data = array( 0 => 'log label', // if applicable 1 => 'log message', // or array / array representation of object 2 => 'path/to/file.php : line_number', 3 => '' // log type ('log', 'error', 'warn', etc) ); ``` Then you would convert this data to a header by doing something like this: ``` php header('X-ChromePhp-Data: ' . base64_encode(utf8_encode(json_encode($data)))); ``` Check out the source at: https://github.com/ccampbell/chromephp/blob/master/ChromePhp.php to see exactly what is going on.
Author
Owner

@stof commented on GitHub (Feb 19, 2012):

OK, so we need to create a big array and set it as a single header.

do you have an idea about how we could handle the context array provided with Monolog messages ? for all messages, we are able to pass a string message and an array of context (for instance, we can use it to log the SQL query and the array of bound parameters). For FirePHP, we currently send array('message' => $message, 'context' => $context) as logged data but maybe something better can be done for ChromePHP ?

<!-- gh-comment-id:4045168 --> @stof commented on GitHub (Feb 19, 2012): OK, so we need to create a big array and set it as a single header. do you have an idea about how we could handle the context array provided with Monolog messages ? for all messages, we are able to pass a string message and an array of context (for instance, we can use it to log the SQL query and the array of bound parameters). For FirePHP, we currently send `array('message' => $message, 'context' => $context)` as logged data but maybe something better can be done for ChromePHP ?
Author
Owner

@stof commented on GitHub (Feb 19, 2012):

@ccampbell btw, does the extension change the user agent or add a custom request header that we could use to send the ChromePHP header only for browsers that have ChromePHP (thus avoiding issues with IE that has a lower limit for the header size) ?

<!-- gh-comment-id:4045503 --> @stof commented on GitHub (Feb 19, 2012): @ccampbell btw, does the extension change the user agent or add a custom request header that we could use to send the ChromePHP header only for browsers that have ChromePHP (thus avoiding issues with IE that has a lower limit for the header size) ?
Author
Owner

@ccampbell commented on GitHub (Feb 20, 2012):

Right now I do not add any additional headers client side, but I will add it if it will be useful to you. You could also do a UA check to make sure it is Chrome before setting the header maybe?

<!-- gh-comment-id:4046875 --> @ccampbell commented on GitHub (Feb 20, 2012): Right now I do not add any additional headers client side, but I will add it if it will be useful to you. You could also do a UA check to make sure it is Chrome before setting the header maybe?
Author
Owner

@stof commented on GitHub (Feb 20, 2012):

well, we could detect Chrome, but it would even be better if we know that it is Chrome with ChromePHP.

Btw, I saw a weird thing when testing it. For the error level message, a stack trace inside the extension was added to the console message, whereas other levels were clean. Is it a bug in the extension ? You can reproduce it by accessing monolog/tests/Monolog/Functional/Handler/FirePHPHandlerTest.php when using the code in my PR linked above.

<!-- gh-comment-id:4046917 --> @stof commented on GitHub (Feb 20, 2012): well, we could detect Chrome, but it would even be better if we know that it is Chrome with ChromePHP. Btw, I saw a weird thing when testing it. For the error level message, a stack trace inside the extension was added to the console message, whereas other levels were clean. Is it a bug in the extension ? You can reproduce it by accessing `monolog/tests/Monolog/Functional/Handler/FirePHPHandlerTest.php` when using the code in my PR linked above.
Author
Owner

@ccampbell commented on GitHub (Feb 20, 2012):

I noticed this too, I believe this is something that Chrome added to the console in Chrome 17. If you do any console.error() regardless of if it is a javascript error it shows a js stack trace.

You can reproduce by simply opening up the console:
Error stacktrace

So I'm not sure if there is any way around it, but I will see.

<!-- gh-comment-id:4046969 --> @ccampbell commented on GitHub (Feb 20, 2012): I noticed this too, I believe this is something that Chrome added to the console in Chrome 17. If you do any console.error() regardless of if it is a javascript error it shows a js stack trace. You can reproduce by simply opening up the console: ![Error stacktrace](http://f.cl.ly/items/3T1e421Y0r2b3o1T2q1H/Screen%20shot%202012-02-19%20at%208.06.47%20PM.png) So I'm not sure if there is any way around it, but I will see.
Author
Owner

@Seldaek commented on GitHub (Feb 20, 2012):

@stof the problem in IE was only caused by having too many headers I think, not very large ones like in this case, but that said there might be a limit there that I didn't hit. Anyway having a custom header of some sort when ChromePHP is enabled would be quite nice.

<!-- gh-comment-id:4049805 --> @Seldaek commented on GitHub (Feb 20, 2012): @stof the problem in IE was only caused by having too many headers I think, not very large ones like in this case, but that said there might be a limit there that I didn't hit. Anyway having a custom header of some sort when ChromePHP is enabled would be quite nice.
Author
Owner

@stof commented on GitHub (Feb 20, 2012):

@Seldaek I updated the PR to detect Chrome at least.

<!-- gh-comment-id:4052727 --> @stof commented on GitHub (Feb 20, 2012): @Seldaek I updated the PR to detect Chrome at least.
Author
Owner

@AndreBaumeier commented on GitHub (Jun 12, 2014):

Is there a documentation entry for what exact chrome extension the ChromePHPHandler was built? I am lucky to found this issue, because there are multiple extensions claiming to be (a) chrome php logger.

<!-- gh-comment-id:45844319 --> @AndreBaumeier commented on GitHub (Jun 12, 2014): Is there a documentation entry for what exact chrome extension the ChromePHPHandler was built? I am lucky to found this issue, because there are multiple extensions claiming to be (a) chrome php logger.
Author
Owner

@stof commented on GitHub (Jun 12, 2014):

The readme has a link to the extension website

<!-- gh-comment-id:45844507 --> @stof commented on GitHub (Jun 12, 2014): The readme has a link to the extension website
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#15
No description provided.