-
Notifications
You must be signed in to change notification settings - Fork 672
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
writing logs to different files under different folders #1107
Labels
question
Further information is requested
Comments
Hi. Did you take a look at this snippet in the documentation: Creating independent loggers with separate set of handlers? A combination of from loguru import logger
task_log_info = {
"zg": ("zerodhaGeneral", "zerodhaGeneral.log"),
"zm": ("Master-zerodha", "ZerodhaAsMaster-Orders.log"),
"zc": ("Child-Zerodha", "ZerodhaAsChild-Orders.log"),
}
for task_id, (folder_name, log_file_name) in task_log_info.items():
def log_filter(record, task_id=task_id):
return record["extra"].get("task_id") == task_id
log_file = f"logs/{folder_name}/{log_file_name}"
logger.add(log_file, filter=log_filter)
logger_zg = logger.bind(task_id="zg")
logger_zm = logger.bind(task_id="zm")
logger_zc = logger.bind(task_id="zc")
logger_zg.info("Goes into zg folder only")
logger_zm.info("Goes into zm folder only")
logger_zc.info("Goes into zc folder only") Make sure to use the appropriate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to log under finders in separate folders.
But it is writing the logs in same file, when I do:
I also have tried like below, but it is also writing in same file only. What am i doing wrong?
The text was updated successfully, but these errors were encountered: