Skip to content

Can logs be written during the compression method? #1333

Open
@dorschw

Description

@dorschw

Hi, thanks for maintaining this great library.

We use add()'s compression argument to upload the log at its closing.
We found out that logging inside the compression method doesn't result in any logs being written.

Is there any way to log this way, or is it just impossible due to an infinite loop potential? (closing a log file, trying to write its success/failure message to another log to another log file, close the other log file...)

Otherwise, can we log the message only to some handlers? (using filter?)

Thanks

from pathlib import Path

from loguru import logger

logger.remove()
def upload_log(path: str|Path) -> None:
    try:
        ...
        logger.info(f"Uploading log file {path}") # never logged
    except:
        logger.exception(f"Failed uploading {path}") # never logged

logger.add(
        Path('/tmp/some_log.log'),
        compression=upload_log,  # called once the file is closed or rolled over
    )
logger.info("just some log") # will show in the file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions