Skip to content

How can I modify file name without changing log structure and use UTC standard? #128

Closed
@VitorCioletti

Description

I've been reading the docs and trying some things out for a few hours and could not do the following.

Create files using UTC and without timing: errors_2019-08-15_.log
Logs in UTC structured like this: 2019-08-15 17:02:16.267 | {LEVEL} | {MESSAGE}.

I've tried this code taken directly from docs and does not seems to work. (And is missing a ) after .utcnow())

logger.add(sys.stderr, format="{extra[utc]} {message}")
logger = logger.patch(lambda record: record["extra"].update(utc=datetime.utcnow())

Error:

--- Logging error in Loguru Handler #2 ---
Record was: {'elapsed': datetime.timedelta(microseconds=531720), 'exception': None, 'extra': {}, 'file': '__init__.py', 'function': 'escuta', 'level': 'INFO', 'line': 35, 'message': 'Servidor escutando...', 'module': '__init__', 'name': 'servidor.endpoint', 'process': '26045', 'thread': '140735874732992', 'time': datetime(2019, 8, 15, 17, 9, 41, 368329, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=75600), '-03'))}
Traceback (most recent call last):
  File "/Users/vitor.morais/Documents/Projetos/futuro-configurador/configurador/venv/lib/python3.7/site-packages/loguru/_handler.py", line 119, in emit
    formatted = precomputed_format.format_map(formatter_record)
KeyError: 'utc'
--- End of logging error ---

How can I do it?

Thanks!

Metadata

Assignees

No one assigned

    Labels

    featureRequest for adding a new feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions