You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
When I use the logger I can see the logs formatted and colored in the console (PyCharm)
But, when opening the actual file, I get unformatted raw ASCII. See pic below.
How can I fix this? Tried to open in many different txt editors, all seem to get the same result, including opening in PyCharm itself.
MacOS 14.3.1
In PyCharm console (during runtime or debugging)
When opening the actual file:
code:
if __name__ == '__main__':
logger.add("my_logger.log", rotation="03:30", colorize=True,
format="<green>{time}</green> <level>{message}</level>")
logger.info("logging some info")
logger.debug("logging some debug stuff")
logger.error("logging error")
exit(1)
The text was updated successfully, but these errors were encountered:
Hi @shlomi93 ,
I am not sure, but colorize=True is not really needed. I've set it to False and it works as you want.
Here is a code:
fromloguruimportloggerif__name__=='__main__':
logger.add("my_logger.log", rotation="03:30", colorize=False,
format="<green>{time}</green> <level>{message}</level>")
logger.info("logging some info")
logger.debug("logging some debug stuff")
logger.error("logging error")
Log file:
2024-03-20T16:30:30.973518+0300 logging some info
2024-03-20T16:30:30.974060+0300 logging some debug stuff
2024-03-20T16:30:30.974191+0300 logging error
As indicated by @smuglik (thanks), the colorize=True makes little sense with log files. This is because the colored logs on your terminal are implemented using ANSI escape sequences, but these color codes are not intended for files.
The files does not conventionally support ANSI codes. There is no way to natively colorize the content of a file. If you want to see colors, the ANSI code would need to be reinterpreted and converted somehow, for example using a VS Code extension: ANSI Colors.
Hi,
When I use the logger I can see the logs formatted and colored in the console (PyCharm)
But, when opening the actual file, I get unformatted raw ASCII. See pic below.
How can I fix this? Tried to open in many different txt editors, all seem to get the same result, including opening in PyCharm itself.
MacOS 14.3.1
In PyCharm console (during runtime or debugging)
When opening the actual file:
code:
The text was updated successfully, but these errors were encountered: