python logging string formatting

前端 未结 3 2108
隐瞒了意图╮
隐瞒了意图╮ 2021-01-04 14:09

I am using python\'s log formatter to format log records and i have a fmt value of

fmt = \"[%(filename)s:%(lineno)s] %(message)s\"

What i w

3条回答
  •  生来不讨喜
    2021-01-04 14:32

    Option 1

    Start here: http://docs.python.org/library/logging.html#formatter-objects

    You'll create your own customized subclass of Formatter that provides it's own unique format method.

    Then you must be sure to call setFormatter() in each of your Handlers so that they use your new formatter.

    Option 2

    Create your own subclass of LogRecord with the additional property.

    Subclass Logger and override makeRecord to create your new subclass of LogRecord.

    Provide a customized format that uses this new property value.

提交回复
热议问题