Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSCommon: add custom formatter for debug log records #4433

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

jcbrill
Copy link
Contributor

@jcbrill jcbrill commented Oct 13, 2023

Add a custom formatter to the MSCommon/common.py debug logging that accepts an optional class name.

Changes:

  • Add support for optional extra dictionary for the python logging.
  • Allow passing 'classname' via the extra dictionary and creating the log records with '%(classname)s.%(funcName)s' for class methods.
  • Add a method to populate and return the extra dictionary.
  • Add a boolean constant indicating if debugging is enabled or not.

Example code demonstrating functionality:

from SCons.Tool.MSCommon.common import (
    debug,
    debug_extra,
    DEBUG_ENABLED,
)

class DebugExample:

    debug_extra = None
    
    info = {
        '1': 'One',
        '2': 'Two',
        '3': 'Three',
    }

    @classmethod
    def setup(cls):
        cls.debug_extra = debug_extra(cls)

    @classmethod
    def debug_dump(cls):
        for key, val in cls.info.items():
            debug('info: key=%s, val=%s', key, val, extra=cls.debug_extra)

    @classmethod
    def hello_world(cls):
        debug('Hello, World!')
        debug('Hello, World!', extra=cls.debug_extra)
        if DEBUG_ENABLED:
            cls.debug_dump()

DebugExample.setup()
DebugExample.hello_world()

Example output (sent to stdout):

debug: 02338ms:SConstruct:hello_world#90: Hello, World!
debug: 02339ms:SConstruct:DebugExample.hello_world#91: Hello, World!
debug: 02339ms:SConstruct:DebugExample.debug_dump#86: info: key=1, val=One
debug: 02339ms:SConstruct:DebugExample.debug_dump#86: info: key=2, val=Two
debug: 02339ms:SConstruct:DebugExample.debug_dump#86: info: key=3, val=Three

The third in a sequence of smaller PRs from #4409.

Internal changes only: no documentation or test updates necessary.

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

…ccepts an optional class name.

Changes:
- Add support for optional extra dictionary for the python logging.
- Allow passing 'classname' via the extra dictionary and creating the log records with '%(classname)s.%(funcName)s' for class methods.
- Add a method to populate and return the extra dictionary.
- Add a boolean constant indicating if debugging is enabled or not.
@bdbaddog bdbaddog added the MSVC Microsoft Visual C++ Support label Oct 13, 2023
@bdbaddog
Copy link
Contributor

What's going to use this?
Will this change what's output in the SCONS_MSCOMMON_DEBUG ?

@jcbrill
Copy link
Contributor Author

jcbrill commented Oct 14, 2023

What's going to use this?
Will this change what's output in the SCONS_MSCOMMON_DEBUG ?

When debug messages are issued from a class method (static or instance) the class name is prefixed to the method name.

Same debug statements with and without extra argument from classmethod function.

debug: 02338ms:SConstruct:hello_world#90: Hello, World!                <- without classname
debug: 02339ms:SConstruct:DebugExample.hello_world#91: Hello, World!   <- with classname

The WIP code changes have a non-trivial number of class/instance method debug calls. It simply provides more information in the debug log.

@bdbaddog bdbaddog merged commit 807cac7 into SCons:master Oct 16, 2023
4 of 6 checks passed
@mwichmann mwichmann added this to the 4.6 milestone Oct 16, 2023
@jcbrill jcbrill deleted the jbrill-mscommon-debug branch November 21, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MSVC Microsoft Visual C++ Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants