Skip to content

Commit a9a4268

Browse files
committed
add functionality for changing default log level
fixes #75
1 parent 97a84f1 commit a9a4268

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

Bot/bot.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import platform
33
import re
4+
import sys
45
import threading
56
import time
67
import tkinter as tk
@@ -14,20 +15,21 @@
1415
from Bot import config as cfg
1516
from Bot import functions as fe
1617

17-
log_level = "TRACE"
18-
log_format = "[{time}] [{level}] {name}:{function}:{line} - {message}"
18+
config = cfg.ConfigHandler("config.properties") # type: ignore
19+
20+
log_level = config.get_log_level()
1921
logger.add(
2022
"client.log",
2123
level=log_level,
22-
format=log_format,
24+
format="[{time}] [{level}] {name}:{function}:{line} - {message}",
2325
colorize=False,
2426
backtrace=True,
2527
diagnose=True,
2628
rotation="1 day",
2729
retention="31 days",
2830
)
2931

30-
config = cfg.ConfigHandler("config.properties") # type: ignore
32+
logger.add(sys.stderr, level=log_level)
3133

3234
# When cargo hold is full, the ship will dock up and unload cargo, undock and warp to another belt
3335
cargo_loading_time_adjustment = config.get_cargo_loading_time_adjustment()
@@ -676,5 +678,6 @@ def start_function() -> None:
676678

677679
def start() -> None:
678680
logger.info("Starting bot")
681+
logger.trace("Hi")
679682
# Start Tkinter Window
680683
root.mainloop()

Bot/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def __init__(self, config_path): # type: ignore
2222
self.config = configparser.ConfigParser()
2323
self.config.read(config_path)
2424

25+
def get_log_level(self) -> str:
26+
return self._get_setting("log_level", self.config.get, "INFO") # type: ignore
27+
2528
def get_hardener_keys(self) -> List[str]:
2629
keys = self._get_setting("hardener_keys", self.config.get, "")
2730
return [key.strip() for key in keys.split(",") if key.strip()]

config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[SETTINGS]
2+
log_level = INFO
23
mining_runs =
34
mining_hold =
45
mining_yield =

0 commit comments

Comments
 (0)