Skip to content

Commit

Permalink
🐛 fix: update logwatch error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
megasanjay committed Sep 19, 2024
1 parent a24df7a commit 6c5d234
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions utils/logwatch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
import contextlib
import config
from colorama import just_fix_windows_console, Fore, Back, Style

Expand Down Expand Up @@ -51,40 +52,47 @@ def info(self, message: str):
"""Send an info message to the logwatch server"""
if self.print:
print(Fore.CYAN + message + Style.RESET_ALL)
requests.post(self.drain, json={"level": "info", "message": message})
with contextlib.suppress(Exception):
requests.post(self.drain, json={"level": "info", "message": message})

def error(self, message: str):
"""Send an error message to the logwatch server"""
if self.print:
print(Fore.RED + message + Style.RESET_ALL)
requests.post(self.drain, json={"level": "error", "message": message})
with contextlib.suppress(Exception):
requests.post(self.drain, json={"level": "error", "message": message})

def warn(self, message: str):
"""Send a warning message to the logwatch server"""
if self.print:
print(Fore.YELLOW + message + Style.RESET_ALL)
requests.post(self.drain, json={"level": "warning", "message": message})
with contextlib.suppress(Exception):
requests.post(self.drain, json={"level": "warning", "message": message})

def debug(self, message: str):
"""Send a debug message to the logwatch server"""
if self.print:
print(Fore.BLUE + message + Style.RESET_ALL)
requests.post(self.drain, json={"level": "debug", "message": message})
with contextlib.suppress(Exception):
requests.post(self.drain, json={"level": "debug", "message": message})

def critical(self, message: str):
"""Send a critical message to the logwatch server"""
if self.print:
print(Back.RED + Fore.WHITE + message + Style.RESET_ALL)
requests.post(self.drain, json={"level": "critical", "message": message})
with contextlib.suppress(Exception):
requests.post(self.drain, json={"level": "critical", "message": message})

def trace(self, message: str):
"""Send a trace message to the logwatch server"""
if self.print:
print(Style.DIM + message + Style.RESET_ALL)
requests.post(self.drain, json={"level": "trace", "message": message})
with contextlib.suppress(Exception):
requests.post(self.drain, json={"level": "trace", "message": message})

def time(self, message: str):
"""Send a time message to the logwatch server"""
if self.print:
print(Back.GREEN + Fore.WHITE + message + Style.RESET_ALL)
requests.post(self.drain, json={"level": "time", "message": message})
with contextlib.suppress(Exception):
requests.post(self.drain, json={"level": "time", "message": message})

0 comments on commit 6c5d234

Please sign in to comment.