Jump to content

Chrome Php Logger


Soma
 Share

Recommended Posts

Chrome Php Logger

Module to log useful details directly in your Chrome JS console. You can inspect most as objects and see infos or values.

To enable logging with this module you have to enable debug modue in config.php. If debug is set to false in config.php, it will not output any log.
Important: It is not recommended to enable it on live stage, as it reveal infos you might not want everybody to see, although it's not obvious as it requires the ChromePhp Extension installed and enabled.

- render time
- memory consumption
- cpu usage
- current user infos

- current user roles 

- current user permissions
- current page with all its fields and their value and field settings
- page cache/loaded on request count
- fuel
- modules loaded
- Server vars etc.

- Cookies

- Requests
- mySQL query log


When installed you can also use ChromePhp static methods to output your own data in all your templates or modules:
 

ChromePhp::log($page->somefield);


Note:
This module requires the ChromePhp Extension installed to see the log in the Javascript console.
More infos can be found on http://chromephp.com

Download:

Modules Directory: http://modules.processwire.com/modules/chrome-php-logger/
Github: https://github.com/s...ChromePhpLogger

post-100-0-36865000-1355361658_thumb.png

  • Like 12
Link to comment
Share on other sites

First of all, Soma, this looks VERY nice! Will install it right now :)

One thing that might be worth mentioning is that since Windows doesn't have getrusage() implemented (correct me if I'm wrong) this might cause some problems in Win-environment. Might be worth checking if it's available first and possibly even providing an alternative solution?

  • Like 1
Link to comment
Share on other sites

Good job Soma!

I like the way you're thinking - I had a module with just slightly less functionality coming up, this week even :D. But now I don't need to find time to finish it as you've already done things bigger and better.

One thing I'd like to see is a little if-statement to disable this when $this->config->debug is false. That would prevent internal structures being displayed at production stage if (when!) debug-mode has been properly disabled.

  • Like 2
Link to comment
Share on other sites

One thing I'd like to see is a little if-statement to disable this when $this->config->debug is false. That would prevent internal structures being displayed at production stage if (when!) debug-mode has been properly disabled.

+1 for this; and I as well wanted to package ChromePHP into a module... You beat me to it, will install this ASAP :)

  • Like 1
Link to comment
Share on other sites

Good one soma!

One thing I'd like to see is a little if-statement to disable this when $this->config->debug is false

I think it would be enough to have it enabled only for logged in superusers.

  • Like 1
Link to comment
Share on other sites

Thanks guys. Yes definately want to implement some of those.

Yes the CPU test doesn't work on Windows. I don't have windows host so I couldn't test, but will implement a check definately. Would be helpful if someone has/knows a script for Windose.

I wasn't sure about superuser only. Because if you want to test not Logged in or with another user...

I will add the config true test.

Sorry guys to get it done before you. We need some board to check in if somebody starts on a module so people can check and see if already something is in work. Although this took me 1 evening lol.

Link to comment
Share on other sites

Just pushed an update to support config true, and added check for getrusage support.

To enable logging with this module you have to enable debug modues in config.php. If debug is set to false in config.php, it will not output any log.

Important: It is not recommended to enable it on live stage, as it reveal infos you might not want everybody to see, although it's not obvious as requires the ChromePhp Extension installed and enabled.

  • Like 1
Link to comment
Share on other sites

I wasn't sure about superuser only. Because if you want to test not Logged in or with another user...

I will add the config true test.

This is what I was thinking too. And the database queries are not logged if debug=false as well.

I see you've decided not to output anything in the admin.. I guess that's because most of the data already is visible there? And while the module adds no hooks in the admin, it does make ChromePhp available for use - so nevermind, just thinking aloud here :).

Sorry guys to get it done before you. We need some board to check in if somebody starts on a module so people can check and see if already something is in work. Although this took me 1 evening lol.

With small modules like this one there shouldn't be a problem. I think I even managed to learn something from the few hours I spent with this one. About PW itself and that I tend to overcomplicate things (had a couple of unnecessary config vars and a little abstraction layer to support other plugins as well later on). Sometimes (well, most of the time) it would be better to get something released and then keep on making it better - if there really is any need after all.

I'm trying to keep this in mind: "If you’re not embarrassed when you ship your first version you waited too long." (see ma.tt/2010/11/one-point-oh/ for the whole essay). A rule not to be followed by people implementing safety measures to nuclear power plants though.

But if I was to start building something bigger, it would be nice to know if someone else is already working on the same thing. That would of course be useful to us mere mortals with somewhat smaller modules too. Not all of us are able to get these kind of useful things from scratch to release during one evening like you are Soma ;).

  • Like 1
Link to comment
Share on other sites

Oops, big fat ugly 500 server error. Trouble is, it's shared hosting, so I don't have access to error logs. (Works alright on Win 7 development system, though.)

Since when? Works fine here and have no clue what causes the error on your side.

Link to comment
Share on other sites

Just pushed an update.

update to version 0.0.3, some improvements and refactoring

- Improved a lot on some page/user fields parsing to give better and deeper results with page fields and file fields. Also shows now fields that are empty and writes "null" in the log.

- Fixed issue with some in admin request getting logged still.

@Soma, me neither. Just installed on remote server and it didn't like it. Will try to troubleshoot some more tomorrow.

I can image something with getrusage() on your hosting having a problem? Not sure though what else.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Hey Soma,

Just went to install via the modules manager and got this notice (obviously not a big deal, but nice to fix):

Notice: Undefined variable: success in /site/modules/ModulesManager/ModulesManager.module on line 393

BUT the following is a show stopper:

 

There seems to be a problem with downloading or writing the module.

Link to comment
Share on other sites

  • 2 weeks later...
  • 5 months later...

Hi Soma, This thing is sweet and adds a lot for my needs. It's giving me an error when caching is enabled on a page. I get the below error:

Notice: Trying to get property of non-object in /app/www/sites/delucas/site/modules/ChromePhpLogger/ChromePhpLogger.module on line 223 Fatal error: Call to a member function getIterator() on a non-object in /app/www/sites/delucas/site/modules/ChromePhpLogger/ChromePhpLogger.module on line 223

Link to comment
Share on other sites

Thanks jonathan, I will add a check to exit on cached pages. Haven't tested so far with cache on, and if logged in there's no cache. Also I thought ChromePhpLogger only executes when logged in anyway so I'm a bit stumped.

Edit: But remember now that I let it on to test with guest or other users. But with cached pages there's no things to debug/log  :D

Link to comment
Share on other sites

Ehrm.. I'm looking into this closer and now reading again your post, it's not an error but a only a notice. Further it's in a strange place where it cycles files/images field and I can't reproduce this and can't think of anything atm.

Also it seems I get tricked by my own modules an PW. This actually works with cached pages?? Which means even if the page is cached and I'm not logged in it shows the details. Long time since I wrote the module but I think it's simply that the module loads the infos to output as PW even with cache on needs to know what page it's loading". Funny. I would have thought it wouldn't work with cache. Well then with ProCache it wouldn't work. :)

Link to comment
Share on other sites

I added a check at that place for and you might want to get the following module file and let me know if it's gone.

But as said I don't understand, that when it gets that far there's should be a object. Can you tell what file or image field there is where it throws the notice, maybe I understand little more. But nothing dramatic.

ChromePhpLogger.module

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...