Logging variable data with new format string

后端 未结 9 2130
别那么骄傲
别那么骄傲 2020-11-28 03:09

I use logging facility for python 2.7.3. Documentation for this Python version say:

the logging package pre-dates newer formatting options such as str

9条回答
  •  迷失自我
    2020-11-28 03:35

    The easier solution would be to use the excellent logbook module

    import logbook
    import sys
    
    logbook.StreamHandler(sys.stdout).push_application()
    logbook.debug('Format this message {k}', k=1)
    

    Or the more complete:

    >>> import logbook
    >>> import sys
    >>> logbook.StreamHandler(sys.stdout).push_application()
    >>> log = logbook.Logger('MyLog')
    >>> log.debug('Format this message {k}', k=1)
    [2017-05-06 21:46:52.578329] DEBUG: MyLog: Format this message 1
    

提交回复
热议问题