[RFC] Allow to configure exception formatter#86
[RFC] Allow to configure exception formatter#86blueyed wants to merge 5 commits intoDelgan:masterfrom
Conversation
|
I'm not sure to follow what is wrong with #59, is there a problem with the Pytest workaround provided? Some exceptions that are displayed while they should not? Thanks for the suggestion but I don't want def formatter(record):
fmt = "{time} {name} - {message}"
if record["exception"] is not None:
record["extra"]["formatted_exception"] = my_exception_formatter(record["exception"])
fmt += " {extra[formatted_exception]}\n"
return fmt
logger.add(sys.stderr, format=formatter) |
It is not really compatible from what I can tell, since exceptions are added to the message - this at least does not really work when migrating from logging to loguru. (However I might have understood the intention there) As for this PR I've just thought that processing could be skipped in general if not required for example.
I see.. then I will look into removing this from here, IIRC there are other useful bits in it. Your example code looks like it would do the job, but is a bit more involved (but fine). |
Ok, yes, I see, sorry. This is because the formatter in So, when
The I think this would produce the same result that your proposition. However, this implies that
Yes, but I'm not worried about that. The exception formatter is instantiated only once, while adding the handler, it's not a problem. When calling |
You could set it via private methods directly. Otherwise your information is what I've seen also. My plan for an improved caplog fixture would be to e.g. use a raw handler and make that available also. Haven't looked into it more yet though. |
How could I? It would require to inspect the
I don't know exactly what you have in mind, improvements are much welcome, as long as they don't extend the api just for uncommon use cases. 😉 |
TODO:
with self._lockblock, but I think that is OK (initially added there in blueyed@04aba79#diff-4446c03371d87929a4cefc5c88a52f36R764)Came across this when looking at #59, i.e. when you want to be compatible to
logging, no exceptions should be added also.