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

Better debug log output... #17

Open
jedie opened this issue Feb 21, 2019 · 2 comments
Open

Better debug log output... #17

jedie opened this issue Feb 21, 2019 · 2 comments

Comments

@jedie
Copy link

jedie commented Feb 21, 2019

I have made a simple log handler for 'suds.transport' that will print the binary output a little bit better to the console.

The normal output:

grafik

With this hacked handler:

grafik

The source code is here: django-oscar/django-oscar-docdata#33

But it's a better place to include this into the suds project, isn't it?

Any interest here? Then I would try to make an pull request.

@phillbaker
Copy link
Member

@jedie thanks for opening an issue! Given Python's structure of separating logging handlers from loggers and the specific constants in the handler you wrote (e.g. HIDE_SETTING_NAMES), I'm not sure that specific logginghandler makes sense in this library.

What do you think about documenting how to build similar custom handlers in the readme? e.g. adding a section similar to:

class SudsLogHandler(logging.StreamHandler):
    def emit(self, record):
        try:
            msg = self.format(record)

            # Note: We get the "suds.transport" log output as strings.
            # e.g.: MESSAGE is only a string representation of bytes, 
            # so reformat newlines:
            msg = msg.replace("\\n", "\n")

            # Evaluate specific attributes
            for attr in ['foo', 'bar']:
                attr_value = getattr(settings, attr, None)
                if attr_value:
                    msg = msg.replace(settings_value, "***")

            # Do the output with some newlines:
            stream = self.stream
            stream.write(self.terminator)
            stream.write(msg)
            stream.write(self.terminator)
            self.flush()
        except Exception:
            self.handleError(record)

import sys, logging
logger = logging.getLogger('suds.transport')
logger.setLevel(logging.DEBUG)
logger.addHandler(SudsLogHandler(sys.stdout))

@jedie
Copy link
Author

jedie commented Feb 22, 2019

The first question would be if there is any interest at all in including this in the project. Then we could see if we could improve it ;)

One question would be, is there a way to get the raw bytes in the log handler? Because there is only the string representation of bytes and we must handle escapes...

HIDE_SETTING_NAMES

This is from django settings. It's just about filtering username and password.
It doesn't make sense to solve this in the same way here.

Maybe we can just add a list of "sensible values" as log handler arguments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants