-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlogging.py
More file actions
33 lines (23 loc) · 841 Bytes
/
logging.py
File metadata and controls
33 lines (23 loc) · 841 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
31
32
33
# -*- coding: utf-8 -*-
import os
import sys
import appdirs
import logbook.more
from . import __title__ as appname
class StreamHandler(logbook.more.ColorizingStreamHandlerMixin,
logbook.StreamHandler):
pass
def issue_logging():
"""Logs to disk only when error occurs"""
def factory(record, handler):
return logbook.FileHandler(LOG_FILE, level='DEBUG',
mode='w', bubble=True)
return logbook.FingersCrossedHandler(factory, bubble=True)
LOG_DIR = appdirs.user_log_dir(appname.lower())
LOG_FILE = os.path.join(LOG_DIR, appname.lower() + '.log')
if not os.path.exists(LOG_DIR):
os.makedirs(LOG_DIR, 0o700)
sh = StreamHandler(sys.stdout, level='NOTICE', bubble=True)
sh.push_application()
issue_logging().push_application()
log = logbook.Logger(appname)