Skip to content

Commit

Permalink
Better debug logging/support
Browse files Browse the repository at this point in the history
  • Loading branch information
AddisonG committed Dec 3, 2021
1 parent 5143794 commit eb6d544
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions timtamcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
STDOUT_FORMAT = '%(asctime)s [%(levelname)s] - %(message)s'

logger = logging.getLogger(__name__)
logging.basicConfig(filename='timtamcam.log', level=logging.INFO, format=LOGFILE_FORMAT)


class TimTamCam(SlackBot):
"""
Watches the Tim Tams. Ever vigilant.
"""

def __init__(self):
self.setup_logging()
def __init__(self, debug=False):
if debug:
self.setup_logging(logging.DEBUG)
else:
self.setup_logging(logging.INFO)
logger.info("Tim Tam Bot starting!")

super().__init__(bot_token)
Expand Down Expand Up @@ -84,14 +85,16 @@ def setup_scales(self):
self.hx.reset()
self.hx.tare()

def setup_logging(self):
def setup_logging(self, level=logging.INFO):
# Log to a file
logger.setLevel(logging.INFO)
logging.basicConfig(filename='timtamcam.log', format=LOGFILE_FORMAT)
logger.setLevel(level)

# Log to stdout
formatter = logging.Formatter(fmt=STDOUT_FORMAT)
log_handler_stdout = logging.StreamHandler(sys.stdout)
log_handler_stdout.setFormatter(formatter)
log_handler_stdout.setLevel(level)
logger.addHandler(log_handler_stdout)

def alert(self, num_timtams: float):
Expand Down Expand Up @@ -210,7 +213,7 @@ def run(self):
# sys.argv[1:]
args = parser.parse_args()

bot = TimTamCam()
bot = TimTamCam(debug=args.debug)
bot.run()

exit(0)

0 comments on commit eb6d544

Please sign in to comment.