Skip to content

Commit

Permalink
JASCIS-225 - change the default output level to WARNING and add quiet…
Browse files Browse the repository at this point in the history
… and verbose options for all commands. This affects the screen output only.
  • Loading branch information
duncanwp committed Aug 1, 2016
1 parent b8217cc commit 1f3cd88
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cis/cis_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def main():
except IOError as e:
# If we don't have permission to write to the log file, all we can do is inform the user
# All future calls to the logging module will be ignored (?)
print(("WARNING: Unable to write to the log: %s" % e))
print("WARNING: Unable to write to the log: %s" % e)
logging.captureWarnings(True) # to catch warning from 3rd party libraries

try:
Expand Down
2 changes: 1 addition & 1 deletion cis/logging.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ args=(os.path.join(os.path.expanduser('~'), 'cis.log'),)
[handler_screen]
class=StreamHandler
formatter=simple
level=INFO
level=WARNING
args=(sys.stdout,)
13 changes: 13 additions & 0 deletions cis/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def initialise_top_parser():
The parser to which all arguments are initially passed
"""
parser = argparse.ArgumentParser("cis")
# Add verbosity arguments to the root parser
verbosity_group = parser.add_mutually_exclusive_group()
verbosity_group.add_argument("-v", "--verbose", action='count')
verbosity_group.add_argument("-q", "--quiet", action='store_true')

subparsers = parser.add_subparsers(dest='command')
plot_parser = subparsers.add_parser("plot", help="Create plots")
add_plot_parser_arguments(plot_parser)
Expand Down Expand Up @@ -966,6 +971,14 @@ def parse_args(arguments=None):
# sys.argv[0] is the name of the script itself
arguments = sys.argv[1:]
main_args = parser.parse_args(arguments)
# Firstly deal with logging verbosity - in case we log anything in the validation
if main_args.quiet:
logging.getLogger('screen').setLevel(logging.ERROR)
elif main_args.verbose == 1:
logging.getLogger('screen').setLevel(logging.INFO)
elif main_args.verbose == 2:
logging.getLogger('screen').setLevel(logging.DEBUG)

main_args = validators[main_args.command](main_args, parser)

return main_args
9 changes: 6 additions & 3 deletions doc/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ The following should be displayed::
version Display the CIS version number
optional arguments:
-h, --help show this help message and exit
-h, --help Show this help message and exit
-v, --verbose Increase the level of logging information output to screen to include 'Info' statements
-vv All log messages will be output to the screen including 'Debug' statements
-q --quiet Suppress all output to the screen, only 'Error' messages will be displayed (which are always fatal).


There are 8 commands the program can execute:
Expand All @@ -35,8 +38,8 @@ There are 8 commands the program can execute:
* ``version`` which is used to display the version number of CIS


If an error occurs while running any of these commands, you may wish to check the log file 'cis.log'; the default
location for this is the current user's home directory.
If an error occurs while running any of these commands, you may wish to increase the level of output using the verbose
option, or check the log file 'cis.log'; the default location for this is the current user's home directory.

LSF Batch Job Submission
------------------------
Expand Down
4 changes: 3 additions & 1 deletion doc/whats_new_1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ CIS 1.4 features
``valid_min`` or ``valid_max`` attributes is also masked appropriately.
* CloudSat ``missing`` and ``missop`` attributes are now read and combined to mask out values which don't conform to the
inequality defined.

* New verbose and quiet flags allow for control over how much CIS commands output to the screen. The default verbosity
has also changed so that by default only warnings and errors will be output to the screen. The full debug output
remains for the cis.log file.

Bugs fixed
==========
Expand Down

0 comments on commit 1f3cd88

Please sign in to comment.