getlogbook / logbook

A cool logging replacement for Python.
http://logbook.readthedocs.org
Other
1.48k stars 165 forks source link

Format placeholders #263

Open JokerQyou opened 6 years ago

JokerQyou commented 6 years ago

I read through the documentation site but did not find a single line of code mentioning about string format. So I assumed the basic concepts are the same. But when I go ahead and try it, things does not work as expected:

Python 3.6.5 (default, Mar 30 2018, 06:42:10)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging, sys, logbook
>>> logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
>>> logging.debug('Hi %s', 'world')
DEBUG:root:Hi world
>>> logbook.StreamHandler(sys.stdout).push_application()
>>> logbook.debug('Hi %s', 'world')
[2018-06-09 13:01:12.360139] DEBUG: Generic: Hi %s
>>> logbook.__version__
'1.4.0'
>>> logbook.debug('Hi {}', 'world')
[2018-06-09 13:02:14.765765] DEBUG: Generic: Hi world
>>>

It seems like logbook does not support string format placeholders %s, %d, etc., while the stdlib logging does. It's this an intended behavior? If so, would it make sense to document this difference so people coming from logging could adjust their expectation?

vmalloc commented 6 years ago

@JokerQyou Logbook uses new-style formatting:

logger.debug("Message is {}", "message")

The code you attached is using logging redirect, which is mostly an interoperability feature to make sure built-in logging logs will make their way into logbook. If you use Logbook, your own code should emit logs using logbook loggers and not logging ones...

wsw70 commented 6 years ago

@vmalloc I think the question was also about the available formatting attributes (?) If so I opened a similar issue (https://github.com/getlogbook/logbook/issues/276)