Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Commit 65248c5

Browse files
slinksofthdiogenes
authored andcommitted
Add exception handler to log uncaught exceptions
1 parent a1aaaf2 commit 65248c5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

kytos/core/controller.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@
4646
__all__ = ('Controller',)
4747

4848

49+
def exc_handler(_, exc, __):
50+
"""Log uncaught exceptions.
51+
52+
Args:
53+
exc_type (ignored): exception type
54+
exc: exception instance
55+
tb (ignored): traceback
56+
"""
57+
logging.basicConfig(filename='errlog.log',
58+
format='%(asctime)s:%(pathname)'
59+
's:%(levelname)s:%(message)s')
60+
logging.exception('Uncaught Exception: %s', exc)
61+
62+
4963
class Controller:
5064
"""Main class of Kytos.
5165
@@ -128,6 +142,7 @@ def __init__(self, options=None, loop=None):
128142
#: Now you can access the enabled napps with:
129143
#: from napps.<username>.<napp_name> import ?....
130144
sys.path.append(os.path.join(self.options.napps, os.pardir))
145+
sys.excepthook = exc_handler
131146

132147
def enable_logs(self):
133148
"""Register kytos log and enable the logs."""

0 commit comments

Comments
 (0)