Details

    • Type: Improvement Improvement
    • Status: Development in progress
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.5
    • Fix Version/s: DEV backlog
    • Component/s: Administration
    • Labels:
    • Testing Instructions:
      Hide
      1. go to "Site administration/Development/Debugging" and activate "debugonlyselected".
      2. Select a user from the users box on the right side and click on "Add". The user should appear on the left side.
      3. Repeat the previous step for all users you want to see the debug messages. It could be normal users or admins.
      4. Select the debug settings below the user selector.
      5. Login as one of the selected users.
      6. Force some error messages e.g.: some senseless lines in a view.php or so. The error messages should be shown to the user.
      7. Login as admin again and remove this user from the list: Select the user on the left side and click on "Remove".
      8. Login as this user again and the error messages should disappear.
      Show
      go to "Site administration/Development/Debugging" and activate "debugonlyselected". Select a user from the users box on the right side and click on "Add". The user should appear on the left side. Repeat the previous step for all users you want to see the debug messages. It could be normal users or admins. Select the debug settings below the user selector. Login as one of the selected users. Force some error messages e.g.: some senseless lines in a view.php or so. The error messages should be shown to the user. Login as admin again and remove this user from the list: Select the user on the left side and click on "Remove". Login as this user again and the error messages should disappear.
    • Affected Branches:
      MOODLE_25_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-36687_master
    • Rank:
      46188

      Description

      Hi,
      I think there should be a possibility to activate the debug mode only for a special defined group of users.
      So you can switch on the debug mode on productive systems without disturbing the work of the rest of users.
      I implemented it temporary as admin tool and integrated it into the settings page "admin/settings/development.php" and into the "lib/setup.php" to activate it.
      I think it is an important improvement of the debug mode.
      Best regards
      Andreas

        Activity

        Hide
        Rajesh Taneja added a comment -

        Thanks Andreas, for reporting this and providing a patch.

        It make sense to have debug option on for few users and surely will help lot of admins.
        I just gave a quick glance on it and will be nice to have it in core.

        Can you please add documentation to code, as it's missing at few places like:
        https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R185

        Also, we don't use mixed as datatype https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R111

        It will be great if you can improve the documentation, so we can take it forward.

        FYI:
        Please refer Documentation and comments standards followed by moodle.

        Show
        Rajesh Taneja added a comment - Thanks Andreas, for reporting this and providing a patch. It make sense to have debug option on for few users and surely will help lot of admins. I just gave a quick glance on it and will be nice to have it in core. Can you please add documentation to code, as it's missing at few places like: https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R185 Also, we don't use mixed as datatype https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R111 It will be great if you can improve the documentation, so we can take it forward. FYI: Please refer Documentation and comments standards followed by moodle.
        Hide
        Andreas Grabs added a comment -

        Hi Rajesh,
        thank you for the quick response!
        I cleaned up the code a bit.
        The function with mixed return is just a copy of the core function.
        There is even the same documentation .
        Best regards
        Andreas

        Show
        Andreas Grabs added a comment - Hi Rajesh, thank you for the quick response! I cleaned up the code a bit. The function with mixed return is just a copy of the core function. There is even the same documentation . Best regards Andreas
        Hide
        Rajesh Taneja added a comment -

        Thanks for updating the code, Andreas.

        By the look of it all looks nice, although while testing this I can see debug config is showing opposite configuration and not respecting debugonlyselected.

        Steps to reproduce:

        1. Have two browsers Chrome (with admin) and FF with user
        2. As admin add user to list and enable debugonlyselected and all debug options
        3. Click save.
        4. All debug options are unselected, but as user I can see debug message.
        5. Click save again and debug options are selected automatically.

        Will have a look at it again to spot the problem. Seems to be something happening with debug_temp and debug options (probably caching)

        Show
        Rajesh Taneja added a comment - Thanks for updating the code, Andreas. By the look of it all looks nice, although while testing this I can see debug config is showing opposite configuration and not respecting debugonlyselected. Steps to reproduce: Have two browsers Chrome (with admin) and FF with user As admin add user to list and enable debugonlyselected and all debug options Click save. All debug options are unselected, but as user I can see debug message. Click save again and debug options are selected automatically. Will have a look at it again to spot the problem. Seems to be something happening with debug_temp and debug options (probably caching)
        Hide
        Andreas Grabs added a comment -

        Hi Rajesh,
        Thank you for this good tip!
        The problem was that the settings page uses the same variables as there are depend on the value of $CFG->debugonlyselected.
        Now I renamed the config names in the settingspage. I added a prefix "cfg" (debug -> cfgdebug and so on).
        The needed values for debugging without the prefix "cfg" now are set independently.
        Best regards
        Andreas

        Show
        Andreas Grabs added a comment - Hi Rajesh, Thank you for this good tip! The problem was that the settings page uses the same variables as there are depend on the value of $CFG->debugonlyselected. Now I renamed the config names in the settingspage. I added a prefix "cfg" (debug -> cfgdebug and so on). The needed values for debugging without the prefix "cfg" now are set independently. Best regards Andreas
        Hide
        Rajesh Taneja added a comment -

        Thanks for fixing this Andreas,
        Sorry for getting back to you on this, but seems few more tings can be improved:

        1. AFAIK we don't have to set php setting https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R54. This should be taken care by lib/setup.php
        2. Name of the configuration debugmodus, adding Helen to see if this if fine.
        3. Might be nice to add few comments https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R79, explaining debug is disabled or so.
        4. Probably function name can be initialise debug_settings or so https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R76. Also, php doc for this can be improved.
        5. https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R112 Globals are not used and hence can be removed.
        6. It might be nice to use html_writer for html. https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R190
        7. Few functions are not documented https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R251 https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R313
        Show
        Rajesh Taneja added a comment - Thanks for fixing this Andreas, Sorry for getting back to you on this, but seems few more tings can be improved: AFAIK we don't have to set php setting https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R54 . This should be taken care by lib/setup.php Name of the configuration debugmodus, adding Helen to see if this if fine. Might be nice to add few comments https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R79 , explaining debug is disabled or so. Probably function name can be initialise debug_settings or so https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R76 . Also, php doc for this can be improved. https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R112 Globals are not used and hence can be removed. It might be nice to use html_writer for html. https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R190 Few functions are not documented https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R251 https://github.com/grabs/moodle/compare/master...MDL-36687_master#L2R313
        Hide
        Andreas Grabs added a comment -

        Hi Rajesh,
        before I go forward I wonder about the creation of a lib/debuglib.php. Currently there is no such file and the binding of an admin/tool into core in the current way isn't really good, is it?
        The only one file I use in my tool is the lib.php. In my opinion this file could be located as lib/debuglib.
        After this I could prefix my functions with "debug_" without breaking the rules.
        A few words to your mentioned points. Most of them you are right. The nr.6) is just a copy of the core code but I can use html_writer.
        Andreas

        Show
        Andreas Grabs added a comment - Hi Rajesh, before I go forward I wonder about the creation of a lib/debuglib.php. Currently there is no such file and the binding of an admin/tool into core in the current way isn't really good, is it? The only one file I use in my tool is the lib.php. In my opinion this file could be located as lib/debuglib. After this I could prefix my functions with "debug_" without breaking the rules. A few words to your mentioned points. Most of them you are right. The nr.6) is just a copy of the core code but I can use html_writer. Andreas
        Hide
        Helen Foster added a comment -

        Raj, thanks for adding me as a watcher.

        Looking at the attached screenshot of this new feature, I'm wondering whether it's really necessary to be able to select particular users from the complete list of site users, or whether we could go for a much simpler setting?

        An example of a similar setting elsewhere in Moodle is displayloginfailures, where you can select Administrators, Administrators and Teachers, or Everybody.

        Another similar setting is notifyloginfailures, where you can select particular admin users or managers.

        As for the name of this new setting, my suggestion is:

        Display debug messages to

        with admin users and managers listed as possible options.

        Show
        Helen Foster added a comment - Raj, thanks for adding me as a watcher. Looking at the attached screenshot of this new feature, I'm wondering whether it's really necessary to be able to select particular users from the complete list of site users, or whether we could go for a much simpler setting? An example of a similar setting elsewhere in Moodle is displayloginfailures, where you can select Administrators, Administrators and Teachers, or Everybody. Another similar setting is notifyloginfailures, where you can select particular admin users or managers. As for the name of this new setting, my suggestion is: Display debug messages to with admin users and managers listed as possible options.
        Hide
        Helen Foster added a comment -

        Amending fix version according to instructions in http://docs.moodle.org/dev/Bug_triage

        Show
        Helen Foster added a comment - Amending fix version according to instructions in http://docs.moodle.org/dev/Bug_triage
        Hide
        Rajesh Taneja added a comment -

        Thanks Andreas and Helen,

        @Andreas: I think moving this in lib/debuglib.php makes sense.
        @Helen: You have a good and valid point here. IMO we should consider this to keep it simple and to specific roles, rather then users.

        Leaving it for Andreas to decide. I am sure this will be of help to lot of users.

        Show
        Rajesh Taneja added a comment - Thanks Andreas and Helen, @Andreas: I think moving this in lib/debuglib.php makes sense. @Helen: You have a good and valid point here. IMO we should consider this to keep it simple and to specific roles, rather then users. Leaving it for Andreas to decide. I am sure this will be of help to lot of users.
        Hide
        Andreas Grabs added a comment -

        Hi Helen,
        thank you for you feedback but I have a slightly different view of these things.
        1) In my opinion the use of roles for debugging is a bad idea. I think debugging should start as early as possible. Also capability checks have some potential situations for debugging and we really don't need debugging for debugging . The check of debugging users in my way is really simple and can be done at an early time of start.
        2) Your suggestion to use a config setting "Display debug messages to" is just the same thing as I do. What is your reason that only admin users and managers should be able to get debug messages? There are many situations in which "normal" users should get debug messages. Especially in the support area we often need to switch debug messages on for a particular user who even hasn't any especially rights. So any user is a potential debug user.
        If we put the things from my admin/tool/debuguser into a core lib so we could save the plugin overhead.
        Best regards
        Andreas

        Show
        Andreas Grabs added a comment - Hi Helen, thank you for you feedback but I have a slightly different view of these things. 1) In my opinion the use of roles for debugging is a bad idea. I think debugging should start as early as possible. Also capability checks have some potential situations for debugging and we really don't need debugging for debugging . The check of debugging users in my way is really simple and can be done at an early time of start. 2) Your suggestion to use a config setting "Display debug messages to" is just the same thing as I do. What is your reason that only admin users and managers should be able to get debug messages? There are many situations in which "normal" users should get debug messages. Especially in the support area we often need to switch debug messages on for a particular user who even hasn't any especially rights. So any user is a potential debug user. If we put the things from my admin/tool/debuguser into a core lib so we could save the plugin overhead. Best regards Andreas
        Hide
        Helen Foster added a comment -

        Andreas, thanks for your explanation. I've never come across a use-case for wanting to turn on debugging for just one user. Has anyone posted about it on moodle.org?

        Perhaps watchers of this issue can comment with their opinions on whether it should be possible to select one user from the complete list of site users, or whether a simpler setting is sufficient.

        Show
        Helen Foster added a comment - Andreas, thanks for your explanation. I've never come across a use-case for wanting to turn on debugging for just one user. Has anyone posted about it on moodle.org? Perhaps watchers of this issue can comment with their opinions on whether it should be possible to select one user from the complete list of site users, or whether a simpler setting is sufficient.
        Hide
        Andreas Grabs added a comment -

        Hi Helen,

        if you want to find some errors on a production system so you never want to show the debug messages for all users. This is just more a feature for administrators and supporters than for developers.
        Sometimes errors appear only on a single account. So an admin or supporter could switch on debugging for this user, than look for the error messages and switch it of again.
        Currently in this case most admins put some lines into the config.php to enable debuging for this user but it is not a good way.
        My first try was to create a plugin for this (https://moodle.org/plugins/view.php?id=462). But there are missing some hooks to activate debugging in this way.
        It would be really great to get this into core.

        Best regards
        Andreas

        Show
        Andreas Grabs added a comment - Hi Helen, if you want to find some errors on a production system so you never want to show the debug messages for all users. This is just more a feature for administrators and supporters than for developers. Sometimes errors appear only on a single account. So an admin or supporter could switch on debugging for this user, than look for the error messages and switch it of again. Currently in this case most admins put some lines into the config.php to enable debuging for this user but it is not a good way. My first try was to create a plugin for this ( https://moodle.org/plugins/view.php?id=462 ). But there are missing some hooks to activate debugging in this way. It would be really great to get this into core. Best regards Andreas
        Hide
        David Mudrak added a comment - - edited

        I agree with Helen on this. I would even personally vote for just a simple checkbox at the debugging setting screen like "Display to site admins only" and it would work even if the admin is logged in as (masquerading) some other user. http://en.wikipedia.org/wiki/KISS_principle

        Show
        David Mudrak added a comment - - edited I agree with Helen on this. I would even personally vote for just a simple checkbox at the debugging setting screen like "Display to site admins only" and it would work even if the admin is logged in as (masquerading) some other user. http://en.wikipedia.org/wiki/KISS_principle
        Hide
        Andreas Grabs added a comment -

        Hi David,
        I do not think that it is to complex in my way. It is only checked the user id inside a list like this "1,4,8". In your way you have to check that the current user is an admin. It seems to be more complex than my way.
        The most important thing in my view is that we sometimes need debugging for non admins just only for a special student or teacher and for a short time. We can not assign any user to the admin group just because there is an error.
        Andreas

        Show
        Andreas Grabs added a comment - Hi David, I do not think that it is to complex in my way. It is only checked the user id inside a list like this "1,4,8". In your way you have to check that the current user is an admin. It seems to be more complex than my way. The most important thing in my view is that we sometimes need debugging for non admins just only for a special student or teacher and for a short time. We can not assign any user to the admin group just because there is an error. Andreas
        Hide
        Dan Poltawski added a comment -

        We already have $CFG->debugusers. From config-dist.php:

        // You can specify a comma separated list of user ids that that always see
        // debug messages, this overrides the debug flag in $CFG->debug and $CFG->debugdisplay
        // for these users only.
        // $CFG->debugusers = '2';
        
        Show
        Dan Poltawski added a comment - We already have $CFG->debugusers. From config-dist.php: // You can specify a comma separated list of user ids that that always see // debug messages, this overrides the debug flag in $CFG->debug and $CFG->debugdisplay // for these users only. // $CFG->debugusers = '2';
        Hide
        Rajesh Taneja added a comment -

        I just asked people in Dev chat about this and Dan P, pointed about $CFG->debugusers which actually do similar work.

        Are we replicating this ? Not sure if we should have Admin UI for this setting.

        Show
        Rajesh Taneja added a comment - I just asked people in Dev chat about this and Dan P, pointed about $CFG->debugusers which actually do similar work. Are we replicating this ? Not sure if we should have Admin UI for this setting.
        Hide
        Andreas Grabs added a comment -

        Hi Dan, Rajesh,
        oh, I forgot the existing of this variable.
        But it has a complete other use. It is used in the function debugging() in the lib/weblib.php and not for printing php errors/warnings and so on.
        But you are right, I should use a different name for this variable.
        The next thing is, that it only can be set in the config.php so a quick switching of debug settings in a production environment is not possible.
        Best regards
        Andreas

        Show
        Andreas Grabs added a comment - Hi Dan, Rajesh, oh, I forgot the existing of this variable. But it has a complete other use. It is used in the function debugging() in the lib/weblib.php and not for printing php errors/warnings and so on. But you are right, I should use a different name for this variable. The next thing is, that it only can be set in the config.php so a quick switching of debug settings in a production environment is not possible. Best regards Andreas
        Hide
        Helen Foster added a comment -

        Thanks Dan for the reminder of $CFG->debugusers. I checked the docs and found it was already mentioned!

        http://docs.moodle.org/en/Debugging

        Show
        Helen Foster added a comment - Thanks Dan for the reminder of $CFG->debugusers. I checked the docs and found it was already mentioned! http://docs.moodle.org/en/Debugging
        Hide
        Rajesh Taneja added a comment -

        Hello Andreas,

        IMHO we should have this feature handy and user/admin should be able to set debugging for users.
        As discussed in Dev chat it seems it can go as a plugin and not core feature.
        Probably a good idea to create a admin_debug_plugin and contribute it.

        Show
        Rajesh Taneja added a comment - Hello Andreas, IMHO we should have this feature handy and user/admin should be able to set debugging for users. As discussed in Dev chat it seems it can go as a plugin and not core feature. Probably a good idea to create a admin_debug_plugin and contribute it.
        Hide
        Andreas Grabs added a comment -

        Hi Rajesh,

        I read the chat history and I am confused a bit. What is the problem with this setting ui? It is neither to complex to understand nor any performace killer. There are much more misunderstandable UIs in moodle. Editing such setting in the config.php is not a good way. You could make a typo and the site is down. In the config.php should be only general settings and not such options you need for 5 minutes. By the way there is no setting available currently!
        Your suggested way to implement it as a plugin has some challenges:
        1) Currently there is no hook to get it working.
        2) There is a plugin overhead what is not really needed.
        3) The plugin would create a new settings item inside the menu what is more confusing in the way: why are there two debug settings???
        We really need this feature and I am sure there are a lot of administrators (not developers like Dan!) and supporters who would be glad to have such feature.

        Best regards
        Andreas

        Show
        Andreas Grabs added a comment - Hi Rajesh, I read the chat history and I am confused a bit. What is the problem with this setting ui? It is neither to complex to understand nor any performace killer. There are much more misunderstandable UIs in moodle. Editing such setting in the config.php is not a good way. You could make a typo and the site is down. In the config.php should be only general settings and not such options you need for 5 minutes. By the way there is no setting available currently! Your suggested way to implement it as a plugin has some challenges: 1) Currently there is no hook to get it working. 2) There is a plugin overhead what is not really needed. 3) The plugin would create a new settings item inside the menu what is more confusing in the way: why are there two debug settings??? We really need this feature and I am sure there are a lot of administrators (not developers like Dan!) and supporters who would be glad to have such feature. Best regards Andreas
        Hide
        Rajesh Taneja added a comment -

        Hello Andreas,
        I have added Martin and Michael, to decide if this is a nice core enhancement.

        Show
        Rajesh Taneja added a comment - Hello Andreas, I have added Martin and Michael, to decide if this is a nice core enhancement.
        Hide
        J. Jakob Hauber added a comment -

        Hello Andreas,

        i would love to see this feature in Moodle.
        For development or in a test environment it is no big deal to use config.php for temporary settings.
        But for debugging a productive Moodlesystem (e.g. a client asks for remote support on a running System) it is not a good way to activate debugging for all users.

        In many cases the person who asks for support can't access confip.php. (and the supporter too)

        So this feature would be a great tool for hosting and support Moodle.

        Best
        Jakob

        Show
        J. Jakob Hauber added a comment - Hello Andreas, i would love to see this feature in Moodle. For development or in a test environment it is no big deal to use config.php for temporary settings. But for debugging a productive Moodlesystem (e.g. a client asks for remote support on a running System) it is not a good way to activate debugging for all users. In many cases the person who asks for support can't access confip.php. (and the supporter too) So this feature would be a great tool for hosting and support Moodle. Best Jakob

          People

          • Votes:
            12 Vote for this issue
            Watchers:
            9 Start watching this issue

            Dates

            • Created:
              Updated: