async-worker / aiologger

Asynchronous logging for Python and asyncio
https://async-worker.github.io/aiologger/
MIT License
136 stars 13 forks source link

Formatters do not work #5

Open mbrancato opened 3 years ago

mbrancato commented 3 years ago

The formatter support appears to not support messages and likely other attributes. Here is it not supporting the default formatter and using Python 3.9.5.

import asyncio
import logging
import aiologger

async def testaiolog():
    # The default formatter is '%(message)s'
    f = logging.Formatter()
    logger = aiologger.Logger.with_default_handlers(name="my-logger", formatter=f)
    await logger.info("foo")

asyncio.run(testaiolog())

Result is to stderr:

{"record": {"line_number": 10, "level": "INFO", "file_path": "aiologgertest.py", "function": "testaiolog", "msg": "foo"}, "logged_at": "2021-07-14T14:12:28.313405", "logger_exception": {"type": "<class 'AttributeError'>", "exc": "'LogRecord' object has no attribute 'getMessage'", "traceback": ["File \"/Users/mike/.pyenv/versions/global-3.9.5/lib/python3.9/site-packages/aiologger/handlers/streams.py\", line 80, in emit", "    msg = self.formatter.format(record) + self.terminator", "  File \"/Users/mike/.pyenv/versions/3.9.5/lib/python3.9/logging/__init__.py\", line 663, in format", "    record.message = record.getMessage()"]}}