kopia lustrzana https://github.com/jupyterhub/repo2docker
avoid producing non-JSON output on errors
register a custom excepthook that is called instead of the default traceback formatter. This produces a phase: failed message with the error.pull/97/head
rodzic
4374a1a451
commit
edbb8dc609
|
@ -179,6 +179,17 @@ class Repo2Docker(Application):
|
||||||
|
|
||||||
return argparser
|
return argparser
|
||||||
|
|
||||||
|
def json_excepthook(self, etype, evalue, traceback):
|
||||||
|
"""Called on an uncaught exception when using json logging
|
||||||
|
|
||||||
|
Avoids non-JSON output on errors when using --json-logs
|
||||||
|
"""
|
||||||
|
self.log.error("Error during build: %s", evalue,
|
||||||
|
exc_info=(etype, evalue, traceback),
|
||||||
|
extra=dict(phase='failed'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
args = self.get_argparser().parse_args()
|
args = self.get_argparser().parse_args()
|
||||||
|
|
||||||
|
@ -200,6 +211,8 @@ class Repo2Docker(Application):
|
||||||
self.cleanup_checkout = args.clean
|
self.cleanup_checkout = args.clean
|
||||||
|
|
||||||
if args.json_logs:
|
if args.json_logs:
|
||||||
|
# register JSON excepthook to avoid non-JSON output on errors
|
||||||
|
sys.excepthook = self.json_excepthook
|
||||||
# Need to reset existing handlers, or we repeat messages
|
# Need to reset existing handlers, or we repeat messages
|
||||||
logHandler = logging.StreamHandler()
|
logHandler = logging.StreamHandler()
|
||||||
formatter = jsonlogger.JsonFormatter()
|
formatter = jsonlogger.JsonFormatter()
|
||||||
|
|
Ładowanie…
Reference in New Issue