Skip to content

Commit

Permalink
Catch error when getting logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
shinkuan committed May 2, 2024
1 parent 2112034 commit 0e68849
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions my_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@
def my_sink(message: loguru.Message) -> None:
record = message.record

logger.level("CLICK", no=10, icon="CLICK")
logger.add("akagi.log")
# logger.add(my_sink)

RECORD_LOG_FIELDS = set((LogFields.record_name, LogFields.level))
res = requests.get("https://fastly.jsdelivr.net/gh/shinkuan/RandomStuff/aliyun_log_handler_arg.json", allow_redirects=True)
json_data = json.loads(res.content)

handler = QueuedLogHandler(
**json_data,
fields=RECORD_LOG_FIELDS,
)
game_result_logger = logging.getLogger("game_result_log")
game_result_logger.setLevel(logging.INFO)
game_result_logger.addHandler(handler)
try:
logger.level("CLICK", no=10, icon="CLICK")
logger.add("akagi.log")
# logger.add(my_sink)

RECORD_LOG_FIELDS = set((LogFields.record_name, LogFields.level))
res = requests.get("https://cdn.jsdelivr.net/gh/shinkuan/RandomStuff/aliyun_log_handler_arg.json", allow_redirects=True)
json_data = json.loads(res.content)

handler = QueuedLogHandler(
**json_data,
fields=RECORD_LOG_FIELDS,
)

game_result_logger.addHandler(handler)
except Exception as e:
logger.error(f"Failed to set up log handler: {e}")

def game_result_log(mode_id: int, rank: int, score: int, model_hash: str) -> None:
if any((mode_id is None, rank is None, score is None, model_hash is None)):
Expand Down

0 comments on commit 0e68849

Please sign in to comment.