Skip to content
Snippets Groups Projects
Commit a09a386d authored by Martin Blanchard's avatar Martin Blanchard
Browse files

cli.py: Add a CLI option disabling log record prints

Try to spend the least amount of time handling logging in gRPC thread
executors: do not log to standard output and standard error channels if
'--no-print' is specified (for use in production).
parent 8c7db057
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ import os
import click
import grpc
from buildgrid.settings import LOG_RECORD_FORMAT
from buildgrid.utils import read_file
CONTEXT_SETTINGS = dict(auto_envvar_prefix='BUILDGRID')
......@@ -139,10 +140,12 @@ class BuildGridCLI(click.MultiCommand):
@click.command(cls=BuildGridCLI, context_settings=CONTEXT_SETTINGS)
@click.option('--no-print', is_flag=True, show_default=True,
help="Do not print log records to stdout/stderr.")
@click.option('-v', '--verbose', count=True,
help='Increase log verbosity level.')
@pass_context
def cli(context, verbose):
def cli(context, no_print, verbose):
"""BuildGrid App"""
logger = logging.getLogger()
......@@ -152,14 +155,15 @@ def cli(context, verbose):
for log_filter in logger.filters[:]:
logger.removeFilter(log_filter)
logging.basicConfig(
format='%(asctime)s:%(name)32.32s][%(levelname)5.5s]: %(message)s')
# Do not register a stream handler if no-print is requested:
if not no_print:
logging.basicConfig(format=LOG_RECORD_FORMAT)
else:
logging.basicConfig(format=LOG_RECORD_FORMAT,
handlers=[logging.NullHandler()])
if verbose == 1:
logger.setLevel(logging.WARNING)
elif verbose == 2:
logger.setLevel(logging.INFO)
elif verbose >= 3:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.ERROR)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment