Skip to content

add loguru logger object support#3

Merged
asuiu merged 1 commit intoeSAMTrade:masterfrom
PyRSA:master
Sep 21, 2022
Merged

add loguru logger object support#3
asuiu merged 1 commit intoeSAMTrade:masterfrom
PyRSA:master

Conversation

@PyRSA
Copy link

@PyRSA PyRSA commented Sep 21, 2022

Fixed the issue that when using loguru.logger as the log output object, the log string was not formatted correctly for output

@PyRSA
Copy link
Author

PyRSA commented Sep 21, 2022

use logging

  • code
import logging

from retry import retry

logging_logger = logging.getLogger(__name__)


@retry(tries=3, delay=0.5, max_delay=10, backoff=0.5, logger=logging_logger)
def test_logging_logger():
    def add(a, b):
        return a + b

    assert add(1, '2')
  • out
TypeError: unsupported operand type(s) for +: 'int' and 'str' in __main__.test_logging_logger, retrying in 0.5 seconds...
TypeError: unsupported operand type(s) for +: 'int' and 'str' in __main__.test_logging_logger, retrying in 0.25 seconds...
...

use loguru

  • code
from loguru import logger as loguru_logger
from retry import retry


@retry(tries=3, delay=0.5, max_delay=10, backoff=0.5, logger=loguru_logger)
def test_loguru_logger():
    def add(a, b):
        return a + b

    assert add(1, '2')
  • out

fix before

2022-09-21 16:30:24.383 | WARNING  | retry.api:__retry_internal:50 - %s: %s in %s.%s, retrying in %s seconds...
2022-09-21 16:30:24.883 | WARNING  | retry.api:__retry_internal:50 - %s: %s in %s.%s, retrying in %s seconds...

fix after

2022-09-21 16:30:25.352 | WARNING  | retry.api:__retry_internal:50 - TypeError: unsupported operand type(s) for +: 'int' and 'str' in __main__.test_logging_logger, retrying in 0.25 seconds...
2022-09-21 16:30:25.823 | WARNING  | retry.api:__retry_internal:50 - TypeError: unsupported operand type(s) for +: 'int' and 'str' in __main__.test_logging_logger, retrying in 0.25 seconds...

@asuiu
Copy link
Member

asuiu commented Sep 21, 2022

Although this doesn't meet Python best practices, the Loguru library becomes increasingly popular, and since loguru isn't compatible with logging it makes sense to adapt this lib for those type of logging libraries as well and make it more generic.
Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments