Skip to content

Commit

Permalink
Added logging args and help text
Browse files Browse the repository at this point in the history
  • Loading branch information
kalaspuff committed Oct 8, 2017
1 parent d34cba3 commit edd020e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tomodachi/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def help_command_usage(self) -> str:
'\n'
'Available subcommands:\n'
' run <service ...> [-c <config-file ...>] [--production]\n'
' -c, --config use json configuration files\n'
' -c, --config <files> use json configuration files\n'
' -l, --log <level> specify log level\n'
' --production disable restart on file changes\n'
)

Expand All @@ -48,7 +49,6 @@ def run_command_usage(self) -> str:
return 'Usage: tomodachi.py run <service ...> [-c <config-file ...>] [--production]'

def run_command(self, args: List[str]) -> None:

if len(args) == 0:
print(self.run_command_usage())
else:
Expand Down Expand Up @@ -93,9 +93,10 @@ def run_command(self, args: List[str]) -> None:
index = args.index('-l') if '-l' in args else args.index('--log')
args.pop(index)
if len(args) > index:
logging_level = logging.getLevelName(args.pop(index).upper())
if isinstance(logging_level, int):
log_level = logging_level
try:
log_level = getattr(logging, args.pop(index).upper())
except AttributeError:
pass

logging.basicConfig(format='%(asctime)s (%(name)s): %(message)s', level=log_level)
logging.Formatter(fmt='%(asctime)s.%(msecs).03d', datefmt='%Y-%m-%d %H:%M:%S')
Expand All @@ -104,7 +105,7 @@ def run_command(self, args: List[str]) -> None:

def main(self, argv: List[str]) -> None:
try:
opts, args = getopt.getopt(argv, "hvV ", ['help', 'version', 'version', 'dependency-versions'])
opts, args = getopt.getopt(argv, "hlvV ", ['help', 'log', 'version', 'version', 'dependency-versions'])
except getopt.GetoptError:
self.help_command()
for opt, arg in opts:
Expand Down

0 comments on commit edd020e

Please sign in to comment.