Skip to content

Commit

Permalink
Improve handling of "ansi" option in messages (#197, #198)
Browse files Browse the repository at this point in the history
First, ansi markup in "*args" and "**kwargs" are ignored when used while
"opt(ansi=True)". This caused errors, as such arguments can contains
tags which are not intended to be used as color markups.

Secondly, it strips the color markups present in the "record[message]"
so it can be used somewhere else where the "ansi" context is lost (like
when logs are emitted through socket). Actually, the colors are part of
the handler so it makes sense to strip them from the record.

These change required a whole refactoring of the coloration process. It
has been implemented with optimization in mind: trying to parse the ansi
message only once, then using the generated tokens to colorize the
message appropriately in each handler. It could certainly be improved,
though.
  • Loading branch information
Delgan committed Jan 19, 2020
1 parent 3b66fb5 commit 2616942
Show file tree
Hide file tree
Showing 14 changed files with 751 additions and 455 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
`Unreleased`
============
`Unreleased`_
=============

- Prevent unrelated files and directories to be incorrectly collected thus causing errors during the `retention` process (`#195 <https://github.com/Delgan/loguru/pull/195>`_, thanks `@gazpachoking <https://github.com/gazpachoking>`_).
- Prevent unrelated files and directories to be incorrectly collected thus causing errors during the `retention` process (`#195 <https://github.com/Delgan/loguru/issues/195>`_, thanks `@gazpachoking <https://github.com/gazpachoking>`_).
- Strip color markups contained in ``record["message"]`` when logging with ``.opt(ansi=True)`` instead of leaving them as is (`#198 <https://github.com/Delgan/loguru/issues/198>`_).
- Ignore color markups contained in ``*args`` and ``**kwargs`` when logging with ``.opt(ansi=True)``, leave them as is instead of trying to use them to colorize the message which could cause undesirable errors (`#197 <https://github.com/Delgan/loguru/issues/197>`_).


`0.4.0`_ (2019-12-02)
Expand Down
266 changes: 0 additions & 266 deletions loguru/_ansimarkup.py

This file was deleted.

Loading

0 comments on commit 2616942

Please sign in to comment.