Jump to content

Tracy Debugger


adrian

Recommended Posts

1 hour ago, lpa said:

Any idea why do I get "Error: Unrecognized path" in the console every time I try to run some code?

You need to install the new ProcessTracyConsole helper module. This is installed automatically for new installs of Tracy, but for those upgrading, you need to manually install it. Because you can't directly call a PHP file from the modules directory in PW, it was either this or moving the file to the root of the site and I thought this was cleaner and potential less hassle for the user.

 

Hi @bernhard - glad you're finding the Console panel so useful!

Firstly, a friendly reminder about PW's each():

d($pages->find('id>1')->each("title"));

Depending on your needs, that will give you much nicer output if you are testing a selector. Also useful is ->getArray() and ->getIterator()

Back to topic now :) - thanks for pointing out the issue when converting the console into a new window - that is weird - hopefully I can fix it. Just a note that once the new window is open, it seems to manage the code fine after that.

What I would really like is for Tracy panels to be drag resizable - maybe that's something I should request or build and PR them, but for now, I have made the console panel almost full width. This will be committed shortly, I just want to take a look at that weird code issue when opening in new window as well.

Screen Shot 2016-06-22 at 10.59.54 AM.png

Multiple consoles sounds pretty cool too, but probably not possible without core hacks, but maybe I can come up with something that achieves your needs in a different way. I am giving thought to the idea of a snippets manager so you can save and load snippets - this should certainly help in your case although may not be quite as convenient. Now that the console panel is full width, I think the snippets library can be in a sidebar on the right which should make it easy to switch between snippets.

Thanks again for the feedback.

 

 

  • Like 3
Link to comment
Share on other sites

One issue I ran into today was a clash of Ace editors (using latest Tracy)

i have ace editors on my InputfieldSelectize module, as well as any field that uses that AceExtended inputfield;
seems that i need to disable the tracy console panel to prevent it from affecting the Ace instance.

These 2 files are not loading:

/site/modules/TracyDebugger/ace-editor/theme-monokai.js
/site/modules/TracyDebugger/ace-editor/worker-javascript.js

And getting this error:

NetworkError: Failed to load worker script at "/site/modules/TracyDebugger/ace-editor/worker-javascript.js"

 

  • Like 1
Link to comment
Share on other sites

Thanks @Macrura - I think it should simply be a matter of assigning ACE to a different variable, rather than `editor` which is used in all the setup examples. I'll make this change for the next version. If you could keep an eye out for it and let me know if that solves the problem for you.

 

Link to comment
Share on other sites

New version just committed that takes care of most of the problems/suggestions that @bernhard noted above. The console code is now also saved to LocalStorage as you type. I am also hoping that the conflict issue that @Macrura brought up is also fixed.

Please let me know!

PS - the issue with the garbled code in the "open in window" mode was very painful to fix, but at least I learned a lot more about the inner workings of ACE and the Tracy core from reading through the source code. I discovered a nice shortcut for when you want the "open in window" mode - simply SHIFT+CLICK on an icon in the debug bar to avoid going through the FLOAT mode first.

  • Like 2
Link to comment
Share on other sites

The latest version now contains three different versions of the Tracy core! Yes, it's a pain and I don't want to maintain them either, and hopefully I can ditch one of these versions shortly if PW's SessionHandlerDB module can be tweaked to work with Tracy - more details below.

Stable (now the old 2.3 branch)

  • supports PHP 5.3 and because PW supports 5.3, I'll keep this version included until PW shifts to 5.4.
  • doesn't capture AJAX requests
  • works with the PW core SessionHandlerDB module

Master (this version is actually a version from a couple of months ago now)

  • needs PHP 5.4
  • doesn't capture AJAX requests
  • works with the PW core SessionHandlerDB module

Latest (this is the current dev version, currently 2.4 - I'll keep this fairly up to date)

  • needs PHP 5.4
  • captures AJAX requests
  • it does NOT currently work properly with the PW core SessionHandlerDB module - there are db table field length restrictions, issues with the MYSQL max_allowed_packet setting, and it prevents the capturing of AJAX requests if it's installed. The errors can be fixed by tweaking your sql settings, but you still can't get AJAX requests working.

Yes, the names of these versions are no longer correct. I will be changing these soon, but didn't want to do too much on this at once.

I personally have decided to give up on SessionHandlerDB until it can be tweaked so that it doesn't break the latest version of Tracy. I find the features in the latest Tracy core worth it, but it's up to you guys what you want to do. I'd be curious to hear which version you decide to use.

Let me know if you have any questions.

  • Like 2
Link to comment
Share on other sites

Hi everyone!

Thanks to a tip from Ryan, I now have the latest version of the Tracy core working properly when the core SessionHandlerDB module is installed. This means that I have been able to consolidate the number of packaged versions down to two: Legacy and Master.

Now the only reason not to use Master is if you are running PHP < 5.4.4

I will keep the Master version updated with changes to core after testing to make sure there are no issues.

The module now automatically adjusts your MySQL max_allowed_packet setting so that it is large enough to handle storing the Tracy debug bar data when you have SessionHandlerDB installed. Ryan has changed the "data" field in the "sessions" database table from text to mediumtext and says he'll be adding this to the upgrade routine shortly, but if you have problems with the Master version, please make this change yourself.

Please let me know if you have any problems with the new Master version.

  • Like 5
Link to comment
Share on other sites

I installed the latest version but always got a TracyDebugger class not found error. However, an earlier version works fine, eg.

https://github.com/adrianbj/TracyDebugger/tree/2fbc6537099a3f90b549fcbfc219417949747952

I updated the module through the Upgrades module, but I got the same error on manual install. Things gone bad when I installed the Process Tracy Console I believe, but not sure. I tried entirely uninstall the module and reinstall, but no joy.

  • Like 1
Link to comment
Share on other sites

Hi @tpr - sorry about that - is that working version the last one that works for you? Everything is fine here, so it's hard for me to track this down without more info. Would you mind doing a little debugging - I am honestly not even sure where to start for this one.

Can you please at least post a screenshot of the error so I can see the file and line number that is generating the error?

Thanks!

Link to comment
Share on other sites

No, I just picked one from the past releases. I've sent you the screenshot in PM.

Edit: the last working one is this:

https://github.com/adrianbj/TracyDebugger/tree/144abecbee3e081de99052671c00f392106c6ae7

Edit2: there may be something with this line, commenting out removes the error:

if($this->setMaxAllowedPacket()) $this->session->redirect('./');

 

  • Like 1
Link to comment
Share on other sites

Thanks @tpr - I have decided to remove that setMaxAllowedPacket method in the latest version - it's most likely not going to work for a standard SQL user on most shared hosts anyway.

So, the message for everyone out there is if the debug bar isn't working and you have the PW core SessionHandlerDB module installed, you have three options:

  1. Uninstall SessionHandlerDB
     
  2. Increase your SQL max_allowed_packet setting (in your my.ini or my.cnf file, or via SET GLOBAL max_allowed_packet) - http://stackoverflow.com/a/5688506/1524576
     
  3. Use the "Legacy" option for the Tracy core setting in the module config (not really recommended as you'll be missing out on core updates)

 

  • Like 3
Link to comment
Share on other sites

New Template Editor panel just added!

This is an alternative to the Template Path panel (which I still think is a great option) if you need to edit a live site, which of course you never do :) The difference with this compared to Nico's Template File Editor (http://modules.processwire.com/modules/template-editor/) is that it allows you to test changes without affecting other users currently viewing the site.

Screen Shot 2016-07-04 at 6.51.25 PM.png

Note that there are three buttons:

Test: This will reload the page using the code in the editor - no changes are made to the template file or the code served to all other users of the site.

Push Live: This will save the editor code to the template file, making this a live and permanent change.

Reset: This will reload the page (and the code in the editor) with the code from the saved template file.

Possible use scenarios

  • Use this panel similarly to your dev console for tweaking CSS/HTML - it still requires a page reload, but there are likely less clicks than your normal workflow.
  • Use it to tweak a live site if you're away from your computer and need a quick way to fix something, but want the ability to test first without breaking something temporarily due to a simple syntax error mistake or more serious code mistake.
  • Use it to add debug statements: fl(), bd(), d() etc to your template code without ever touching the actual template files.

This is a first version of this panel - I am looking for feedback and feature/behavior suggestions. At the moment this only lets you edit the template file for the currently viewed page. I am considering adding a dropdown where you can load other files (included files, JS, CSS files etc), but want to see what you guys think.

  • Like 11
Link to comment
Share on other sites

How cool is that?!!!! ?

One little suggestion is to add an orange status bar somewhere when the code differs from the original template file. Otherwise it could happen that you inspect/view other code than all live site users and don't know it

  • Like 1
Link to comment
Share on other sites

5 hours ago, bernhard said:

One little suggestion is to add an orange status bar somewhere when the code differs from the original template file.

This is already implemented - the icon is red when you are viewing code that is different from that in the original template file. 

 

4 hours ago, LostKobrakai said:

I especially dig the last two use-cases. Debugging an issue on the live site by now used to be lot's of if($user==…) statements.

Glad you dig it - pity you don't like it :) 

Btw, the Template Path panel also allows this functionality without adding $user== conditionals - if you haven't checked it out, you should experiment with it also - whether you use it or this new panel depends on how attached you are to your editor, whether you have access to it, or if you want to save the hassle of setting up a "-dev" version of the file and pushing to the server, etc. Probably in most cases I would use this new Template Editor panel for debugging and the Template Path panel for adding/testing new functionality.

  • Like 1
Link to comment
Share on other sites

29 minutes ago, LostKobrakai said:

That's down to my not so perfect english. Thought this would mean a bit more of "liking something" instead of "understanding something".

Your English is just fine :)

I was just taking a dig at you for not clicking "Like". 

English is such a weird language and please note that those definitions of "taking a dig" that I linked to sound a lot stronger than how most people think of it when using that phrase. Ribbing is probably closer to what I was doing.

  • Like 4
Link to comment
Share on other sites

hi adrian,

new website, first module installed: tracy ;) it's really a great tool, thanks again!

today i had the problem of several errors when using the todo-panel, because there where some invalid characters in some of my template sources. it is a folder of my designer using uikit and some other resources... i fixed it by adding the template folder on this line: https://github.com/adrianbj/TracyDebugger/blob/master/TodoPanel.inc#L148

i think it would be a good option to have a textarea to EXCLUDE (or maybe also include?) some folders from being processed. i have lots of todos/hacks/bugs in my template that are not my concern - so this option would be great in two ways: prevent errors like the one i had today and prevent showing todos that do not belong to my work.

  • Like 2
Link to comment
Share on other sites

Hi @bernhard - glad to hear that Tracy is first on your list :)

I am happy to make that ignore list configurable, but I would also like to know what errors you were getting due to those invalid characters. Maybe that also needs some attention?

I am also wondering if perhaps it should be the other way around - maybe it should only process the root of site/templates plus the root level of the scripts and styles subfolders. In other words it would not scan any other site/templates subfolders and also no subfolders with scripts and styles. I would of course make this configurable also as I expect some people change "styles" to "css and "scripts" to "js". I don't want to end up with too many config options, but sometime soon I need to make it easy to export Tracy settings from one install and import into other installs.

 

 

  • Like 1
Link to comment
Share on other sites

The latest version adds a new User Switcher panel that lets you instantly switch to any user (or logout) and then easily switch back to your superuser account. 

It is fairly similar in functionality to the user switcher in @horst's excellent ALIF module, but has the advantage of making the Tracy debug bar available when switched to any user and even when logged out, which can be very useful for debugging.

Screen Shot 2016-07-08 at 6.58.48 PM.png   Screen Shot 2016-07-08 at 6.59.09 PM.png   Screen Shot 2016-07-08 at 6.59.24 PM.png

Obviously there are some security concerns when setting up functionality that can log into other accounts without needing a password. There are several things this panel does to make this safe(r), but the key thing to remember is that setting Tracy to Production mode keeps you safe!

  1. It is completely disabled unless Tracy is specifically set to Development mode. Detect mode won't work and even the "Superuser Force Development Mode" option won't enable it so you can be sure your live sites are safe unless you specifically enable Development Mode for a debugging session.
  2. You need to be a superuser to have access to the panel until a session is started, so even when Development mode is enabled, other users still won't be able to use it.
  3. It only works for the duration of user switcher session (max 60 minutes) and only a superuser can start a session.
  4. Starting the session makes use of PW's CSRF protection.
  5. The switcher session has a unique ID and expiry time which is stored in the database and must match the ID in the user's session.
  6. Once the session has expired, it is no longer possible to switch users. You can manually end the session, or if you forget it will expire automatically based on the session length you set.

As usual, icon colors are meaningful telling you what type of user is currently logged in:

Green: superuser
Orange: non-superuser
Red: guest / logged out

Please let me know how you go with this new panel - hopefully it will be a significant timesaver when checking/debugging your site from other user roles. Also, if you think of any improvements that could make this more secure, or useful, please let me know. I would definitely appreciate an extra set of eyes (or two) to take a look!

This new version also has the following changes:

  1. It removes the need for the separate helper process module for executing the Console Panel code - it will be uninstalled during the upgrade.
  2. I have removed the "Debug Statements" tool in the config settings - I think this is superfluous now that you can easily add debug statements to template files dynamically using the Template Editor Panel. If anyone really wants this back, let me know.
  3. There is also significant cleanup of other sections of code, so please let me know if you notice any issues from these changes.

Have a great weekend!

 

  • Like 5
Link to comment
Share on other sites

This is another great addition to the toolset of your No1 developer helper plugin! Thanx so much!

"...hopefully it will be a significant timesaver when checking/debugging your site from other user roles."

Sure, it will be! The only reason I sometimes used the ALIF module was the user switcher feature. Now we have a more feature rich solution, without needing to install another module.

  • Like 2
Link to comment
Share on other sites

1 hour ago, tpr said:

You just made ALIF deprecated but I think @horst can live with that :)

That's correct!

This is one more example on how things grow in our community: we work together to make it as good as we can.

Someone come up with a good solution for a partial thing. This a) directly help others, it b) inspires other users to new / other solutions, and this, in the end, makes working with our beloved PW a little more better again.

And, in this case, (ALIF and Tracy): from now on, everytime when I will use Tracy, I will have the feeling that a little part of my work is into it. :)

  • Like 7
Link to comment
Share on other sites

  • adrian pinned and locked this topic
  • adrian unpinned and pinned this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...