Project

General

Profile

« Previous | Next » 

Revision 2439

bin/map: Switched to verbosity-level-based system of logging. verbose is now an integer, and debug sets the minimum verbosity to 2.

View differences:

map
80 80
    if end != None: end += start
81 81
    
82 82
    # Debugging
83
    debug = opts.env_flag('debug', False, env_names)
84
    sql.run_raw_query.debug = debug
85
    verbose = debug or opts.env_flag('verbose', not test, env_names)
83
    verbosity = util.cast(int, opts.get_env_var('verbose', 0, env_names))
86 84
    verbose_errors = opts.env_flag('verbose_errors', test or debug, env_names)
85
    if opts.env_flag('debug', False, env_names): verbosity = max(verbosity, 2)
87 86
    opts.get_env_var('profile_to', None, env_names) # add to env_names
88 87
    
89 88
    # DB
......
108 107
    ##
109 108
    
110 109
    # Logging
111
    def log(msg, on=verbose):
112
        if on: sys.stderr.write(msg+'\n')
113
    if debug: log_debug = lambda msg: log(msg, debug)
110
    debug = verbosity >= 2
111
    sql.run_raw_query.debug = debug
112
    def log(msg, level=1):
113
        '''Higher level -> more verbose'''
114
        if level <= verbosity: sys.stderr.write(msg+'\n')
115
    if debug: log_debug = lambda msg, level=2: log(msg, level)
114 116
    else: log_debug = sql.log_debug_none
115 117
    
116 118
    # Parse args
......
420 422
    
421 423
    profiler.stop(row_ct)
422 424
    ex_tracker.add_iters(row_ct)
423
    if verbose:
424
        sys.stderr.write('Processed '+str(row_ct)+' input rows\n')
425
        sys.stderr.write(profiler.msg()+'\n')
426
        sys.stderr.write(ex_tracker.msg()+'\n')
425
    log('Processed '+str(row_ct)+' input rows')
426
    log(profiler.msg())
427
    log(ex_tracker.msg())
427 428
    ex_tracker.exit()
428 429

  
429 430
def main():

Also available in: Unified diff