-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogging_setup.py
More file actions
27 lines (20 loc) · 859 Bytes
/
logging_setup.py
File metadata and controls
27 lines (20 loc) · 859 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
import os
import logging
from logging.handlers import RotatingFileHandler
log = None
roaming_path = os.path.join(os.getenv('APPDATA'), "VATSIM-Discord-RPC")
log_file = roaming_path + "\log.log"
def setup_logging():
if not os.path.exists(roaming_path):
os.makedirs(roaming_path)
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
my_handler = RotatingFileHandler(log_file, mode='a', maxBytes=5*1024*1024,
backupCount=2, encoding=None, delay=0)
my_handler.setFormatter(log_formatter)
my_handler.setLevel(logging.INFO)
log = logging.getLogger('root')
log.setLevel(logging.INFO)
# Avoid adding multiple handlers if setup_logging is called more than once
if not log.handlers:
log.addHandler(my_handler)
return log