From 8694c7a7dc532fb33412aea952db7ce6f10c87c6 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 20 Aug 2018 15:30:51 -0700 Subject: [PATCH] composer-cli should not log to a file by default The user can pass --log /path/to/logfile.log if they want logging enabled. (cherry picked from commit 844ff9998b33697e39dd816bed8fb73eb330793a) --- src/bin/composer-cli | 26 ++++++++++++++++---------- src/composer/cli/cmdline.py | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/bin/composer-cli b/src/bin/composer-cli index 56a9c4cc..65f90f10 100755 --- a/src/bin/composer-cli +++ b/src/bin/composer-cli @@ -29,8 +29,12 @@ from composer.cli.cmdline import composer_cli_parser VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) -def setup_logging(logfile): - # Setup logging to console and to logfile +def setup_logging(logfile=None): + """ Setup logging to console and to an optional logfile + + :param logfile: Optional path to file to store logs in + :type logfile: None or str + """ log.setLevel(logging.DEBUG) sh = logging.StreamHandler() @@ -39,11 +43,12 @@ def setup_logging(logfile): sh.setFormatter(fmt) log.addHandler(sh) - fh = logging.FileHandler(filename=logfile) - fh.setLevel(logging.DEBUG) - fmt = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s") - fh.setFormatter(fmt) - log.addHandler(fh) + if logfile != None: + fh = logging.FileHandler(filename=logfile) + fh.setLevel(logging.DEBUG) + fmt = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s") + fh.setFormatter(fmt) + log.addHandler(fh) if __name__ == '__main__': # parse the arguments @@ -54,9 +59,10 @@ if __name__ == '__main__': print(VERSION) sys.exit(0) - logpath = os.path.abspath(os.path.dirname(opts.logfile)) - if not os.path.isdir(logpath): - os.makedirs(logpath) + if opts.logfile != None: + logpath = os.path.abspath(os.path.dirname(opts.logfile)) + if not os.path.isdir(logpath): + os.makedirs(logpath) setup_logging(opts.logfile) log.debug("opts=%s", opts) diff --git a/src/composer/cli/cmdline.py b/src/composer/cli/cmdline.py index 0dda1c1a..f827e824 100644 --- a/src/composer/cli/cmdline.py +++ b/src/composer/cli/cmdline.py @@ -35,7 +35,7 @@ def composer_cli_parser(): help="Output the raw JSON response instead of the normal output.") parser.add_argument("-s", "--socket", default="/run/weldr/api.socket", metavar="SOCKET", help="Path to the socket file to listen on") - parser.add_argument("--log", dest="logfile", default="./composer-cli.log", metavar="LOG", + parser.add_argument("--log", dest="logfile", default=None, metavar="LOG", help="Path to logfile (./composer-cli.log)") parser.add_argument("-a", "--api", dest="api_version", default="0", metavar="APIVER", help="API Version to use")