-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
33 lines (27 loc) · 883 Bytes
/
log.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
26
27
28
29
30
31
32
33
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import logging
# FIXME: Multiple call not checked, is that ok?
def setup_logger(module_name):
logger = logging.getLogger(module_name)
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch = logging.StreamHandler()
ch.setLevel(logging.WARN)
ch.setFormatter(formatter)
LOG_PATHNAME = os.path.dirname(os.path.abspath(__file__))+'/log'
try:
os.mkdir(LOG_PATHNAME)
except FileExistsError:
pass
try:
LOG_FILENAME = sys.argv[1]+'-qiangke'
except IndexError:
LOG_FILENAME = 'qiangke'
fh = logging.FileHandler('{}/{}.log'.format(LOG_PATHNAME, LOG_FILENAME))
fh.setLevel(logging.INFO)
fh.setFormatter(formatter)
logger.addHandler(ch)
logger.addHandler(fh)