-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloggingModule.py
More file actions
executable file
·30 lines (25 loc) · 990 Bytes
/
loggingModule.py
File metadata and controls
executable file
·30 lines (25 loc) · 990 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
def func():
logging.debug('This is a debug message')
logging.info('This is an info message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical message')
try:
c = 1 / 0
except Exception as e:
logging.exception("Exception occurred", exc_info=True) #exc_info to on/off this log
logging.basicConfig(filename='log.text', filemode='a', level=logging.DEBUG, format='%(asctime)s %(msecs)d - %(process)d - %(levelname)s - %(filename)s:%(funcName)s:%(lineno)d - %(message)s', datefmt='%Y%m%d %H%M%S')
func()
logging.shutdown()
# Log rotation:
#
# from logging.handlers import RotatingFileHandler
#
# logging.basicConfig(
# handlers=[RotatingFileHandler('./my_log.log', maxBytes=200000, backupCount=2)],
# level=logging.DEBUG,
# format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
# datefmt='%Y-%m-%dT%H:%M:%S')