Created
May 8, 2025 22:36
-
-
Save sinkers/6cbde71cc45629bb4d58110e4aa36195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomFormatter(logging.Formatter): | |
def formatTime(self, record, datefmt=None): | |
dt = datetime.fromtimestamp(record.created) | |
if datefmt: | |
return dt.strftime(datefmt) | |
return f"{dt.strftime('%Y-%m-%d %H:%M:%S')}.{int(record.msecs):03d}" | |
logging.basicConfig( | |
level=logging.INFO, | |
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | |
datefmt="%Y-%m-%d %H:%M:%S", | |
) | |
for handler in logging.getLogger().handlers: | |
handler.setFormatter(CustomFormatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")) | |
logger = logging.getLogger(__name__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment