-
Notifications
You must be signed in to change notification settings - Fork 30
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
Logging content of a dict just prints '1970-01-01T01:00:00' #117
Comments
That's "interesting" output, but also that's not how the logging should be used -- you should use the logging.info('Some dict output: {a}', a=1) |
(That said, I can't explain what happens in the second case ;) ) |
Thanks for the reply. I've never seen the name syntax in a logging call. And does not seem to work in a quick test of mine.
|
That syntax is a new string-interpolation syntax in python; the names in (How does the dict syntax ever work? dicts don't have order, so without naming the strings it can't possibly work...?) |
I think we should leave this bug open as an "improve documentation" bug; we don't explicitly describe this syntax (even though it sort-of appears in the examples): http://txaio.readthedocs.io/en/latest/programming-guide.html#logging |
you can do the same with %s syntax eg: logging.debug("foo bar: %(foo)s, %(bar)s", {'foo': 'asdf', 'bar': 'qwerty'}) the .format equivalent of his original code would be to just replace the %s with {} as the .format method does not require variable names be filled in. In that case, just like %s syntax, the substitutions must be in the correct order. the .format system is just a newer form of %s imho. Personally I have been sticking with %s. I only use .format form when working on someone else's code that is using that method. I find it is very useful to log the contents of various variables at points in your code to help debug/monitor how things are working. |
I am a bit confused.
The docs state
When I use the above code with txaio, e.g., because I start to use autoboahn-python, it will stop working. |
txaio is a compatibility library so we can write "the same" code across asyncio and Twisted. The logging system in here is built as a mostly-thin wrapper over Twisted's new logging system, giving us semi-structured logging -- that is, you can completely ignore the format string and just log the This also has speed benefits: because the string interpolation is delayed, un-logged levels (e.g. .trace or .debug) never get interpolated into strings. If you really do want to do your own string-interpolation stuff, you can follow a pattern like this: |
Hmm, actually perhaps I glossed over the original report too quickly -- that code is indeed using the So, either that statement from the docs can't be true, or something has to be done to txaio logging in the case of getting a single string containing "{" characters but no |
Stumbled upon this in my application which uses autobahn-python.
See the following sample code:
Expectation is that the content of the dict is logged in both cases.
Actual output:
Expected output:
The text was updated successfully, but these errors were encountered: