Skip to content

Commit

Permalink
instances.log: add code, that i need to rework
Browse files Browse the repository at this point in the history
  • Loading branch information
kaeeraa committed Oct 21, 2024
1 parent b193834 commit a9022c0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions instances/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@
logger.level("ERROR", color="<red>", icon="💔")
logger.level("CRITICAL", color="<red>", icon="💔")

if any(arg in ["-V", "--verbose"] for arg in argv):
logLevel = "DEBUG"
elif any(arg in ["-VV", "--vomit"] for arg in argv):
logLevel = "TRACE"
else:
logLevel = "INFO"

# Add a file handler with specific configurations
logger.add(
# Generate a unique log filename ({time}_xxxxxxxx.log)
sink=f"logs/{datetime.now().strftime('%Y-%m-%d')}_{randbytes(n=4).hex()}.log",
format="<green>{time:HH:mm:ss:SSS}</green> | "
"<level>{level}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level>",
level=("TRACE" if any(arg in ["-V", "--verbose"] for arg in argv) else "DEBUG"), # Set level based on verbosity
level=logLevel, # Set level based on verbosity
serialize=True, # Enable log serialization
colorize=False, # Disable colorization in file logs
rotation="10 MB", # Rotate logs after reaching 10 MB
Expand All @@ -55,5 +63,5 @@
"{level.icon} | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - "
"<level>{message}</level>",
level=("TRACE" if any(arg in ["-V", "--verbose"] for arg in argv) else "DEBUG"), # Set level based on verbosity
level=logLevel, # Set level based on verbosity
)

0 comments on commit a9022c0

Please sign in to comment.