Coder Social home page Coder Social logo

ChromePHP Handler about monolog HOT 11 CLOSED

seldaek avatar seldaek commented on July 18, 2024
ChromePHP Handler

from monolog.

Comments (11)

stof avatar stof commented on July 18, 2024

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 ?

from monolog.

ccampbell avatar ccampbell commented on July 18, 2024

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.

from monolog.

stof avatar stof commented on July 18, 2024

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 ?

from monolog.

stof avatar stof commented on July 18, 2024

@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) ?

from monolog.

ccampbell avatar ccampbell commented on July 18, 2024

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?

from monolog.

stof avatar stof commented on July 18, 2024

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.

from monolog.

ccampbell avatar ccampbell commented on July 18, 2024

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.

from monolog.

Seldaek avatar Seldaek commented on July 18, 2024

@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.

from monolog.

stof avatar stof commented on July 18, 2024

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

from monolog.

AndreBaumeier avatar AndreBaumeier commented on July 18, 2024

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.

from monolog.

stof avatar stof commented on July 18, 2024

The readme has a link to the extension website

from monolog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.