Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loguru多个logger的实现不大符合loguru的设计逻辑 #14

Open
IanVzs opened this issue Feb 10, 2023 · 0 comments
Open

loguru多个logger的实现不大符合loguru的设计逻辑 #14

IanVzs opened this issue Feb 10, 2023 · 0 comments

Comments

@IanVzs
Copy link
Collaborator

IanVzs commented Feb 10, 2023

或许正确的使用方式

from loguru import logger
from app import hello_loguru
from app2 import hello_loguru2

logger.add("logs/loguru_app_{time:YYYY-MM-DD}.log",
    level="INFO",
    rotation='00:00',
    encoding='utf-8',
    # filter=lambda x: __name__ in x,
    filter="app",
    compression="zip"
)

logger.add("logs/loguru_app2_{time:YYYY-MM-DD}.log",
    level="INFO",
    rotation='00:00',
    encoding='utf-8',
    filter="app2",
    compression="zip"
)
if __name__ == "__main__":
    logger.info("in main")
    hello_loguru.go_logger()
    hello_loguru2.go_logger()

loguru的源码

# _filters.py
def filter_none(record):
    return record["name"] is not None

def filter_by_name(record, parent, length):
    name = record["name"]
    if name is None:
        return False
    return (name + ".")[:length] == parent

def filter_by_level(record, level_per_module):
    name = record["name"]
    while True:
        level = level_per_module.get(name, None)
        if level is False:
            return False
        if level is not None:
            return record["level"].no >= level
        if not name:
            return True
        index = name.rfind(".")
        name = name[:index] if index != -1 else ""
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

No branches or pull requests

1 participant