Replies: 1 comment
-
For example: from logging import Formatter, basicConfig, getLogger
from logging.handlers import RotatingFileHandler
from rich.logging import RichHandler
basicConfig(
level="INFO",
format="%(message)s",
datefmt="[%X]",
handlers=[RichHandler(rich_tracebacks=True)],
)
log = getLogger("rich")
file_handler = RotatingFileHandler("./example.log", mode="w", backupCount=120, delay=True)
fmt = "%(asctime)s %(levelname)9s %(filename)21s:%(lineno)-3s | %(message)s"
formatter = Formatter(fmt=fmt, datefmt="%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(formatter)
log.addHandler(file_handler)
log.info("something") Console:
File:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am currently using rich, and I would like to save my logs to the system while also having them print directly to the console. What is the best way to do this in rich? Will it allow me to see the formatting from the file afterwards when using e.g.
less log.txt
?Beta Was this translation helpful? Give feedback.
All reactions