<s> import json <EOL> _log = [ ] <EOL> enabled = False <EOL> def start_logging ( ) : <EOL> global _log <EOL> global enabled <EOL> _log = [ ] <EOL> enabled = True <EOL> def stop_logging ( ) : <EOL> global enabled <EOL> enabled = False <EOL> def get_log ( ) : <EOL> return json . dumps ( _log , indent = <NUM_LIT:2> ) <EOL> def add_to_log ( obj ) : <EOL> if enabled : <EOL> _log . append ( obj ) <EOL> def log_git ( command , stdin , stdout , stderr ) : <EOL> add_to_log ( { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : command , <EOL> "<STR_LIT>" : stdin , <EOL> "<STR_LIT>" : stdout , <EOL> "<STR_LIT>" : stderr <EOL> } ) <EOL> def log_error ( err ) : <EOL> add_to_log ( { <EOL> "<STR_LIT:type>" : "<STR_LIT:error>" , <EOL> "<STR_LIT:error>" : repr ( err ) <EOL> } ) <EOL> def log_on_exception ( fn ) : <EOL> def wrapped_fn ( * args , ** kwargs ) : <EOL> try : <EOL> fn ( * args , ** kwargs ) <EOL> except Exception as e : <EOL> add_to_log ( { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : repr ( e ) <EOL> } ) <EOL> raise e <EOL> def pprint ( * args ) : <EOL> """<STR_LIT>""" <EOL> import pprint <EOL> for arg in args : <EOL> if isinstance ( arg , str ) : <EOL> print ( arg ) <EOL> else : <EOL> pprint . pprint ( arg ) </s>
