merge redundant code to configure logging

Summary:
public
The code to configure to configure the logging was duplicated, but was not not doing exactly the same thing. This diff makes all the code to call the same configuration function.

Reviewed By: sblackshear

Differential Revision: D2844361

fb-gh-sync-id: 9887cad
master
jrm 9 years ago committed by facebook-github-bot-5
parent 7b9b6841d2
commit 1544819b40

@ -432,7 +432,7 @@ if __name__ == '__main__':
help='Build targets to analyze')
args = parser.parse_args()
utils.configure_logging(args.verbose)
utils.configure_logging(args)
timer = utils.Timer(logging.info)
temp_files = []

@ -32,9 +32,6 @@ MODULE_TO_COMMAND = {
'mvn': ['mvn']
}
FORMAT = '[%(levelname)s] %(message)s'
LOG_FILE = 'toplevel.log'
def get_commands():
"""Return all commands that are supported."""
#flatten and dedup the list of commands
@ -95,16 +92,6 @@ def create_argparser(parents=[]):
return parser
def configure_logging(infer_dir, log_to_stderr):
if log_to_stderr:
logging.basicConfig(level=logging.INFO, format=FORMAT)
else:
logging.basicConfig(level=logging.INFO,
format=FORMAT,
filename=os.path.join(infer_dir, LOG_FILE),
filemode='w')
def main():
to_parse, cmd = split_args_to_parse()
# get the module name (if any), then load it
@ -132,7 +119,7 @@ def main():
if imported_module:
analyze.create_results_dir(args.infer_out)
configure_logging(args.infer_out, args.log_to_stderr)
utils.configure_logging(args)
logging.info('Running command %s', ' '.join(sys.argv))
logging.info('Path to infer script %s (%s)', __file__,
os.path.realpath(__file__))

@ -101,9 +101,6 @@ base_group.add_argument('-l', '--llvm', action='store_true',
help='''[experimental] Analyze C or C++ file using the
experimental LLVM frontend''')
base_group.add_argument('--log_to_stderr', action='store_true',
help='''When set, all logging will go to stderr instead
of the log file''')
base_parser.add_argument('-v', '--version',
help='''Print the version of Infer and exit''',
action=VersionAction)
@ -247,8 +244,6 @@ class Infer:
help_exit('Unknown analysis mode \"{0}\"'
.format(self.args.analyzer))
utils.configure_logging(self.args.debug)
self.javac = jwlib.CompilerCall(javac_args)
if not self.javac.args.version:

@ -45,6 +45,8 @@ BUGS_FILENAME = 'bugs.txt'
IOS_CAPTURE_ERRORS = 'errors'
IOS_BUILD_OUTPUT = 'build_output'
LOG_FILE = 'toplevel.log'
BUCK_INFER_OUT = 'infer'
CLASS_SOURCE_MAP_OUTPUT_FILENAME_OPTION = 'classSourceMapOutputFilename'

@ -58,7 +58,7 @@ def locale_csv_reader(iterable, dialect='excel', **kwargs):
yield [unicode(cell, config.LOCALE) for cell in row]
def configure_logging(debug, quiet=False):
def configure_logging(args):
"""Configures the default logger. This can be called only once and has to
be called before any logging is done.
"""
@ -69,12 +69,14 @@ def configure_logging(debug, quiet=False):
logging.log(logging.TIMING, msg, *args, **kwargs)
logging.timing = timing
if quiet:
logging.basicConfig(level=logging.TIMING, format=FORMAT)
elif not debug:
logging.basicConfig(level=logging.INFO, format=FORMAT)
else:
if args.debug:
logging.basicConfig(level=logging.DEBUG, format=DEBUG_FORMAT)
else:
logging.basicConfig(level=logging.INFO,
format=FORMAT,
filename=os.path.join(args.infer_out,
config.LOG_FILE),
filemode='w')
def elapsed_time(start_time):

Loading…
Cancel
Save