-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqbit-watcher.py
41 lines (34 loc) · 1.11 KB
/
qbit-watcher.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
import os
import logging
import logging.handlers
import sys
from qbit_watcher import MainError
from qbit_watcher.main import main
def create_emergency_logger():
"""
Application will run without I/O available
We need to write in a emergency file if something goes wrong
Emergency file will be in APPDATA
"""
logger = logging.getLogger()
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
log_file_path = "%s\qbit-watcher\emergency.log" % (os.getenv('APPDATA'))
if not os.path.exists(os.path.dirname(log_file_path)):
os.makedirs(os.path.dirname(log_file_path))
file_handler = logging.handlers.RotatingFileHandler(
log_file_path,
maxBytes=(1048576*5),
backupCount=7
)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.setLevel(logging.INFO)
return logger
if __name__ == '__main__':
try:
main()
# Catch all wanted worst case scenario
except (MainError, Exception) as exn:
logger = create_emergency_logger()
logger.error(exn)
sys.exit(1)