-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
25 lines (22 loc) · 977 Bytes
/
logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
from logging import getLogger, Formatter, FileHandler, INFO
from pathlib import Path
import sys
class Logger(object):
def __init__(self):
self.logger = getLogger(__name__)
self.handler = FileHandler(
Path(sys.argv[0]).resolve().parent / "MultiPyAlarm.log"
)
self.handler.setLevel(INFO)
formatter = Formatter("%(asctime)s\t%(levelname)s\t%(message)s")
self.handler.setFormatter(formatter)
self.logger.setLevel(INFO)
# [python]loggerの出力が重複するのを防ぐ - 盆暗の学習記録 https://nigimitama.hatenablog.jp/entry/2021/01/27/084458
if not self.logger.hasHandlers():
self.logger.addHandler(self.handler)
self.logger.propagate = False
def timer(self, action, timer):
self.logger.info(
f"[{action}] message: {timer['message']}, starttime: {timer['starttime']}, endtime: {timer['endtime']}"
)