-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmylog.py
32 lines (25 loc) · 986 Bytes
/
mylog.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
# -*- coding:utf-8 -*-
# NOTSET < DEBUG < INFO < WARNING < ERROR < CRITICAL
import logging
import time
logger = logging.getLogger("simplelog")
logger.setLevel(logging.DEBUG)
def getdate():
current = time.localtime()
date = "{0}{1}{2}{3}{4}{5}".format(current.tm_year,
str(current.tm_mon+100)[-2:],
str(current.tm_mday+100)[-2:],
str(current.tm_hour+100)[-2:],
str(current.tm_min+100)[-2:],
str(current.tm_sec+100)[-2:])
return date
currentdate = getdate()
fh = logging.FileHandler("%s.log" % currentdate)
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s -%(levelname)s - %(message)s")
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)