Display Variables during run

This takes a lot of my debugging time.
During the run of an app, I like to see how a variable is changing. To do this I manually enter echo statements to print out the values I want to see, at the points I need them
It would save me hours a week, if somehow I could specify the variables I want to see and the system echo them for me when ever they change, or just echo every variable as it changes.

If there were 1 enhancement that would make life easier, it is this.

Does anyone have a way to do this?

I know I can see variable values at the end of the session, but not as they change

Thanks for listening

1 Like

I always struggle wit the same. So would be very interesting to see any advice from seasoned developers.

2 Likes

Do you mean

Scriptcase global variable( [myvar] )

or

generic php variable ( $myvar ) ?

1 Like

I can only suggest to log what PHP is doing into a database table, cause the page will not be updated while php is running. so there is no way to output debugging info live to a webpage.

Are you suggesting I manually code the update to this table for each instance I need it, or is there a system method for logging this?

Both and all
$abc
{abc}
[abc]

u can use sc standard logging,
for instance, when a wrong username used , i use
sc_log_add(ā€˜login Failā€™, {lang_login_fail} . {login});

you will find all this records in the log table, sort it by insert datetime desc to view data.

first you need to activate log module from SC.
menu MODULES/LOG/

I never realized that was doable.TY, this is immensely helpful.

not what you asked butā€¦ maybe create a code sniped (that you could insert with hot keys
and the code should

  1. crate a variable (then you can edit the name)
  2. read a global static variable that lets you show or not the echo something like debuging=ā€œtrueā€ o false
  3. and then, if the debuging variable is ā€œtrueā€ echo the variable created, if not do not show it

this would make a little cumbersome your code butā€¦ it could kind of do the trick

I use standard php error logging and send verbose debugging to the php log on the server. I tail that log file to read in the debug.

2 Likes

sound interesting, could elaborate
is php always logging errors? how to configure this?
i appreciate your advice

Yes, please elaborate on how this is done. Sounds like a winning solution

Yes php is usually always logging errors, refer to: PHP: error_log - Manual

I use this in my php code to log whatever I need, if the application debug mode is enabled. That way you can enable/disable debugging with the same toggle in the scriptcase app settings.

if ($this->Db->debug == true) error_log($variable);

Of course with more complex apps you can turn this into a shared function in a library to simplify it further. You can also specify a different log file to keep your own logging separate.

To look at the log, open a terminal window (Iā€™m running osx) and run the following command:

tail -f /Applications/Scriptcase/v9-php73/components/apache/logs/error_log

3 Likes

Thank you. Excellent it works for me when tracking a normal variable.
Had a problem when tracking an array. I tried error_log(print_r($var)) which did not work. After some investigation I found by adding the parameter true IE: error_log(print_r($var,true)) worked well for me.

1 Like