-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.py
More file actions
executable file
·31 lines (27 loc) · 1.05 KB
/
Logger.py
File metadata and controls
executable file
·31 lines (27 loc) · 1.05 KB
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
26
27
28
29
30
31
# -*- coding: UTF-8 -*-
"""
Description: MultiTool
@author: Men Luyao
@date: 2019/9/12
"""
import sys, re, datetime
import logging
import ctypes
from logging.handlers import RotatingFileHandler
from logging.handlers import TimedRotatingFileHandler
# basic_log_path = '/opt/monitor/log' if '-o' in sys.argv else 'log'
task_name = '_'.join(sys.argv[1:]).replace('-', '')
# fl_name = '{}/{}_{}.log'.format(basic_log_path, task_name, datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
fmt = '%(asctime)s\tFile \"%(filename)s\", line %(lineno)s\t%(levelname)s: %(message)s'
logger = logging.getLogger(__name__)
formatter = logging.Formatter(fmt)
logger.setLevel(logging.INFO)
# fh = TimedRotatingFileHandler(fl_name, when='MIDNIGHT', interval=1, backupCount=7, encoding="utf-8") # MIDNIGHT , atTime=datetime.time(0, 0, 0, 0)
# # delete settings
# fh.suffix = '_%Y%-m-%d_%H-%M'
# fh.extMatch = re.compile(r"^_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}$")
# fh.setFormatter(formatter)
# logger.addHandler(fh)
sh = logging.StreamHandler()
sh.setFormatter(formatter)
logger.addHandler(sh)