Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --silent option to ctsm_logging python infrastructure #1941

Closed
ekluzek opened this issue Jan 21, 2023 · 4 comments · Fixed by #1812
Closed

Add --silent option to ctsm_logging python infrastructure #1941

ekluzek opened this issue Jan 21, 2023 · 4 comments · Fixed by #1812
Assignees
Labels
enhancement new capability or improved behavior of existing capability

Comments

@ekluzek
Copy link
Collaborator

ekluzek commented Jan 21, 2023

I'd like to add a "--silent" option to ctsm_logging for our python scripts. This would allow an additional logging level that would suppress warnings, but still abort on error.

The reason this would be helpful is that subset_data writes out a warning if the --dom-pft option is used and for #1812 I'd like the warning to not show up.

@ekluzek ekluzek added enhancement new capability or improved behavior of existing capability type: -discussion labels Jan 21, 2023
@ekluzek ekluzek self-assigned this Jan 21, 2023
@ekluzek
Copy link
Collaborator Author

ekluzek commented Jan 21, 2023

This is simple to do:

index ff51c6d8f..9768fed5f 100644
--- a/python/ctsm/ctsm_logging.py
+++ b/python/ctsm/ctsm_logging.py
@@ -68,6 +68,9 @@ def add_logging_args(parser):
     logging_level.add_argument(
         "-v", "--verbose", action="store_true", help="Output extra logging info"
     )
+    logging_level.add_argument(
+        "-s", "--silent", action="store_true", help="Only output errors"
+    )
 
     logging_level.add_argument(
         "--debug",
@@ -84,6 +87,8 @@ def process_logging_args(args):
         root_logger.setLevel(logging.DEBUG)
     elif args.verbose:
         root_logger.setLevel(logging.INFO)
+    elif args.silent:
+        root_logger.setLevel(logging.ERROR)
     else:
         root_logger.setLevel(logging.WARNING)
 

@ekluzek
Copy link
Collaborator Author

ekluzek commented Jan 21, 2023

Additional error checking could be done to ensure that you don't try to turn more than one of verbose, silent, or debug at once.

@ekluzek
Copy link
Collaborator Author

ekluzek commented Jan 21, 2023

And the doc/design/python_script_user_interface.rst should be updated.

@billsacks
Copy link
Member

Sounds good. There should already be error-checking in place to ensure that only one logging option is chosen, via the use of a mutually-exclusive group:

logging_level = parser.add_mutually_exclusive_group()

One thing I'd change from your proposed solution is that I don't think we should allow the short -s option: we should just have --silent – otherwise we can't use -s for any other purpose in any of our scripts (and there may already be some uses of that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new capability or improved behavior of existing capability
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants