Skip to content

Commit

Permalink
Merge pull request #230 from luigi311/file_logfile
Browse files Browse the repository at this point in the history
Fix logfile
  • Loading branch information
luigi311 authored Feb 22, 2025
2 parents 305fea8 + 8503b08 commit e48533d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

load_dotenv(override=True)

log_file = os.getenv("LOG_FILE", os.getenv("LOGFILE", "log.log"))
mark_file = os.getenv("MARK_FILE", os.getenv("MARKFILE", "mark.log"))


Expand Down
12 changes: 5 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ def should_sync_server(


def main_loop():
log_file = os.getenv("LOG_FILE", os.getenv("LOGFILE", "log.log"))
# Delete log_file if it exists
if os.path.exists(log_file):
os.remove(log_file)

dryrun = str_to_bool(os.getenv("DRYRUN", "False"))
logger.info(f"Dryrun: {dryrun}")

Expand Down Expand Up @@ -229,15 +224,18 @@ def main():
# Remove default logger to configure our own
logger.remove()

log_file = os.getenv("LOG_FILE", os.getenv("LOGFILE", "log.log"))

# Choose log level based on environment
# If in debug mode with a "debug" level, use DEBUG; otherwise, default to INFO.
level = os.getenv("DEBUG_LEVEL", "INFO").upper()

if level not in ["INFO", "DEBUG", "TRACE"]:
logger.add(sys.stdout)
raise Exception("Invalid DEBUG_LEVEL, please choose between INFO, DEBUG, TRACE")

# Add a sink for file logging (with optional rotation) and the console.
logger.add("log.log", level=level, rotation="10 MB")
# Add a sink for file logging and the console.
logger.add(log_file, level=level, rotation="500 MB")
logger.add(sys.stdout, level=level)

run_only_once = str_to_bool(os.getenv("RUN_ONLY_ONCE", "False"))
Expand Down

0 comments on commit e48533d

Please sign in to comment.