Is it possible to modify/append to the output text of an existing Python Logger object?

Viewed 46

I'm using a Python module with a Logger object that outputs logs as so:

INFO:ProgressLogger:Started work. Items to process: 1.
INFO:ProgressLogger:1 items processed. Progress is 100%.

Is there any way to modify the output text of the ProgressLogger object so that it also appends custom text like:

INFO:ProgressLogger:Started work. Items to process: 1. {insert customer text here}
INFO:ProgressLogger:1 items processed. Progress is 100%. {insert customer text here}

I know I can edit the code in the module for the ProgressLogger class so that it can take in custom text values but wondering if there is a simpler way to just append text to an existing Logger object's output?

1 Answers

Loggers don't output information, Handlers do. The output that you showed is controlled by a Formatter, so you may be able do what you need with a custom Formatter subclass. You haven't given enough information to provide any more detail and to determine whether or not it's feasible to do exactly what you want, but almost certainly the custom Formatter would be the way to approach it.

Related