composer-cli should not log to a file by default
The user can pass --log /path/to/logfile.log if they want logging enabled.
This commit is contained in:
parent
773613bc80
commit
d0c4524253
@ -43,8 +43,8 @@ def get_parser():
|
|||||||
help="Output the raw JSON response instead of the normal output.")
|
help="Output the raw JSON response instead of the normal output.")
|
||||||
parser.add_argument("-s", "--socket", default="/run/weldr/api.socket", metavar="SOCKET",
|
parser.add_argument("-s", "--socket", default="/run/weldr/api.socket", metavar="SOCKET",
|
||||||
help="Path to the socket file to listen on")
|
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)")
|
help="Path to optional logfile")
|
||||||
parser.add_argument("-a", "--api", dest="api_version", default="0", metavar="APIVER",
|
parser.add_argument("-a", "--api", dest="api_version", default="0", metavar="APIVER",
|
||||||
help="API Version to use")
|
help="API Version to use")
|
||||||
parser.add_argument("--test", dest="testmode", default=0, type=int, metavar="TESTMODE",
|
parser.add_argument("--test", dest="testmode", default=0, type=int, metavar="TESTMODE",
|
||||||
@ -58,8 +58,12 @@ def get_parser():
|
|||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def setup_logging(logfile):
|
def setup_logging(logfile=None):
|
||||||
# Setup logging to console and to logfile
|
""" 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)
|
log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
sh = logging.StreamHandler()
|
sh = logging.StreamHandler()
|
||||||
@ -68,6 +72,7 @@ def setup_logging(logfile):
|
|||||||
sh.setFormatter(fmt)
|
sh.setFormatter(fmt)
|
||||||
log.addHandler(sh)
|
log.addHandler(sh)
|
||||||
|
|
||||||
|
if logfile != None:
|
||||||
fh = logging.FileHandler(filename=logfile)
|
fh = logging.FileHandler(filename=logfile)
|
||||||
fh.setLevel(logging.DEBUG)
|
fh.setLevel(logging.DEBUG)
|
||||||
fmt = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")
|
fmt = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||||
@ -83,6 +88,7 @@ if __name__ == '__main__':
|
|||||||
print(VERSION)
|
print(VERSION)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if opts.logfile != None:
|
||||||
logpath = os.path.abspath(os.path.dirname(opts.logfile))
|
logpath = os.path.abspath(os.path.dirname(opts.logfile))
|
||||||
if not os.path.isdir(logpath):
|
if not os.path.isdir(logpath):
|
||||||
os.makedirs(logpath)
|
os.makedirs(logpath)
|
||||||
|
Loading…
Reference in New Issue
Block a user