-
Notifications
You must be signed in to change notification settings - Fork 40
/
logging.py
45 lines (40 loc) · 1.2 KB
/
logging.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
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
import sys
import logging
import os
from logging.handlers import RotatingFileHandler
try:
LOG_FILENAME = os.path.splitext(__file__)[0] + ".log"
#LOG_FILENAME = sys.argv[0] + ".log"
except:
LOG_FILENAME = __file__ + ".log"
#logging.basicConfig(
# level=logging.DEBUG,
# format='[%(asctime)s] [%(filename)s:%(lineno)d] [%(levelname)s] %(message)s',
# #datefmt='%a, %d %b %Y %H:%M:%S',
# datefmt='%F %H:%M:%S',
# filename='myapp.log',
# filemode='w+'
#)
#
#logging.debug('This is debug message')
#logging.info('This is info message')
#logging.warning('This is warning message')
logger = logging.getLogger()
Rthandler = RotatingFileHandler(
LOG_FILENAME,
mode='a',
maxBytes = 10 * 1024 * 1024,
backupCount=5
)
#Rthandler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
fmt = '[%(asctime)s] [%(filename)s:%(lineno)d] [%(levelname)-8s] %(message)s',
datefmt = '%F %H:%M:%S'
)
Rthandler.setFormatter(formatter)
logger.addHandler(Rthandler)
logger.setLevel(logging.DEBUG)
logger.critical("This is a critical message.")
logger.warning('This is warning message')
logger.info('This is warning message')