def setup_logging(verbose, logfile): logging.config.fileConfig('logging.conf', disable_existing_loggers=False) logger = logging.getLogger() # we assume here, that there is at least one handler set in basic config and it is the console logger if verbose: logger.handlers[0].setLevel(logging.DEBUG) if logfile: dir_path = os.path.dirname(os.path.realpath(logfile)) os.makedirs(dir_path, exist_ok=True) formatter = Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s") file_handler = FileHandler(logfile, mode='a', encoding=None, delay=False) file_handler.setFormatter(formatter) if verbose: file_handler.level = logging.DEBUG else: file_handler.level = logging.INFO logger.addHandler(file_handler) return logger
def __init__(self, *args): logging.basicConfig(level=logging.DEBUG) self.logger = logging.getLogger(name=__name__) formatter = Formatter(fmt="%(asctime)s %(message)s", datefmt="%Y/%m/%d %p %I:%M:%S") file_handler = FileHandler("/var/log/tamabot.log", "a+") file_handler.level = logging.INFO file_handler.formatter = formatter self.logger.addHandler(file_handler)
def setup_logger(self): logging.basicConfig( level=logging.ERROR, format='%(asctime)s- %(name)s - %(levelname)s - %(message)s') self.logger = logging.getLogger(__name__) file_handler = FileHandler('{0}/log/gazeru.log' .format(self.GAZEL_HOME), 'a+') file_handler.level = logging.INFO file_handler.formatter = Formatter(fmt='%(asctime)s %(message)s', datefmt='%Y/%m/%d %p %I:%M:%S') self.logger.addHandler(file_handler) return self
def _init_logger(self): self.logger = getLogger(__name__) formatter = Formatter(fmt='%(asctime)s [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S') log_level = self.config['loglevel'].lower() log_level = DEBUG if log_level == 'debug' else\ INFO if log_level == 'info' else\ WARNING if log_level == 'warning' else\ ERROR if log_level == 'error' else\ INFO self.logger.setLevel(log_level) stream_handler = StreamHandler() stream_handler.setLevel(log_level) self.logger.addHandler(stream_handler) if self.config['logfile'] != None: file_handler = FileHandler(self.config['logfile'], 'a+') file_handler.level = log_level file_handler.formatter = formatter self.logger.addHandler(file_handler)
import time import logging import slack # ./slack.py from adxl345 import ADXL345 from datetime import datetime from logging import FileHandler, Formatter logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) formatter = Formatter( fmt='%(asctime)s %(message)s', datefmt='%Y/%m/%d %p %I:%M:%S', ) file_handler = FileHandler('log.log', 'a+') file_handler.level = logging.INFO file_handler.formatter = formatter logger.addHandler(file_handler) check_time = 3 # [sec] この秒数を1セットとする sleep_time = 0.1 # [sec] この秒数分check_timeを刻む(*1)(check_time=3, sleep_time=0.1の場合30分割される) t_shake = 0.022 # 揺れたとみなす加速度の閾値 t_count = 7 # (*1)で分割したうちこの数値分t_shakeを超えていたらそのセットが揺れたとみなされる(max: check_time / sleep_time) t_shake_count = 5 # 洗濯が開始されたとみなされるセット数 finish_time = 360 # [sec] この秒数間揺れがなかったら終了とみなす queue_size = int(check_time / sleep_time) adxl345 = ADXL345() axes = adxl345.getAxes(True) base = (axes['x'], axes['y'], axes['z'])