MCPcopy Create free account
hub / github.com/Bitmessage/PyBitmessage / configureLogging

Function configureLogging

src/debug.py:34–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32 logging.critical('Unhandled exception', exc_info=(ex_cls, ex, tb))
33
34def configureLogging():
35 have_logging = False
36 try:
37 logging.config.fileConfig(os.path.join (state.appdata, 'logging.dat'))
38 have_logging = True
39 print "Loaded logger configuration from %s" % (os.path.join(state.appdata, 'logging.dat'))
40 except:
41 if os.path.isfile(os.path.join(state.appdata, 'logging.dat')):
42 print "Failed to load logger configuration from %s, using default logging config" % (os.path.join(state.appdata, 'logging.dat'))
43 print sys.exc_info()
44 else:
45 # no need to confuse the user if the logger config is missing entirely
46 print "Using default logger configuration"
47
48 sys.excepthook = log_uncaught_exceptions
49
50 if have_logging:
51 return False
52
53 logging.config.dictConfig({
54 'version': 1,
55 'formatters': {
56 'default': {
57 'format': u'%(asctime)s - %(levelname)s - %(message)s',
58 },
59 },
60 'handlers': {
61 'console': {
62 'class': 'logging.StreamHandler',
63 'formatter': 'default',
64 'level': log_level,
65 'stream': 'ext://sys.stderr'
66 },
67 'file': {
68 'class': 'logging.handlers.RotatingFileHandler',
69 'formatter': 'default',
70 'level': log_level,
71 'filename': state.appdata + 'debug.log',
72 'maxBytes': 2097152, # 2 MiB
73 'backupCount': 1,
74 'encoding': 'UTF-8',
75 }
76 },
77 'loggers': {
78 'console_only': {
79 'handlers': ['console'],
80 'propagate' : 0
81 },
82 'file_only': {
83 'handlers': ['file'],
84 'propagate' : 0
85 },
86 'both': {
87 'handlers': ['console', 'file'],
88 'propagate' : 0
89 },
90 },
91 'root': {

Callers 2

debug.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected