Skip to content

logging using RichHandler can't save teminal output in the hydra.log file #2804

Answered by QingYunA
QingYunA asked this question in Q&A
Discussion options

You must be logged in to vote

Thx!
Inspired by #2765, by easily revise my code, I replace the original .log file by logging.FileHandler.
The code bellow is a pratically function to generate a logger.

import logging
from rich.logging import RichHandler
import os

def get_logger():
    hydra_path = hydra.core.hydra_config.HydraConfig.get().runtime.output_dir
    job_name = hydra.core.hydra_config.HydraConfig.get().job.name

    file_handler = logging.FileHandler(os.path.join(hydra_path, f"{job_name}.log"))
    rich_handler = RichHandler()

    log = logging.getLogger(__name__)
    log.setLevel(logging.DEBUG)
    log.addHandler(rich_handler)
    log.addHandler(file_handler)
    log.propagate = False
    log.info("Success…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@odelalleau
Comment options

Answer selected by QingYunA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants