[PATCH][LNT] refactor logging code in main for reuse.
Daniel Dunbar
daniel at zuster.org
Thu Oct 10 10:47:16 PDT 2013
Thanks, comments:
#1. Nothing ever uses the sa_logger result, there isn't a good reason to
return it (clients that want it can also always get it themselves).
#2. Doesn't this patch remove the logger from send-run-comparison?
#3. What about just making this a method on the lnt.Instance? You can just
drop the logging support from action_update, as that method should be
rewritten to be instance based anyway.
- Daniel
On Fri, Oct 4, 2013 at 10:21 AM, Chris Matthews <chris.matthews at apple.com>wrote:
> Extract logging code so that it can be called from a few places in main.py.
>
>
> diff --git a/lnt/lnttool/main.py b/lnt/lnttool/main.py
> index
> 2b667bfb97a67d9316f82908f91773073240cf5c..3fb96e5a4eb4879fcccdf9fc9364c7feea22e620
> 100644
> --- a/lnt/lnttool/main.py
> +++ b/lnt/lnttool/main.py
> @@ -15,6 +15,27 @@ import lnt.util.ImportData
> from lnt import testing
> from lnt.testing.util.commands import note, warning, error, fatal
>
> +def setup_logging(level=logging.INFO, sql_level=logging.ERROR):
> + """Setup the LNT loggers.
> + Arguments:
> + level - The logging framework level for use in LNT.
> + show_sql_logging - Logging level for sqlAlchmey.
> + """
> + logger = logging.getLogger("lnt")
> + logger.setLevel(level)
> + handler = logging.StreamHandler(sys.stderr)
> + handler.setFormatter(logging.Formatter(
> + '%(asctime)s %(levelname)s: %(message)s',
> + datefmt='%Y-%m-%d %H:%M:%S'))
> + logger.addHandler(handler)
> +
> + # Enable full SQL logging, if requested.
> + sa_logger = logging.getLogger("sqlalchemy")
> + sa_logger.setLevel(sql_level)
> + sa_logger.addHandler(handler)
> +
> + return logger, sa_logger
> +
> def action_runserver(name, args):
> """start a new development server"""
>
> @@ -56,28 +77,15 @@ view the results.\
>
> input_path, = args
>
> - # Setup the base LNT logger.
> - logger = logging.getLogger("lnt")
> - if opts.debugger:
> - logger.setLevel(logging.DEBUG)
> - handler = logging.StreamHandler(sys.stderr)
> - handler.setFormatter(logging.Formatter(
> - '%(asctime)s %(levelname)s: %(message)s',
> - datefmt='%Y-%m-%d %H:%M:%S'))
> - logger.addHandler(handler)
> -
> - # Enable full SQL logging, if requested.
> - if opts.show_sql:
> - sa_logger = logging.getLogger("sqlalchemy")
> - if opts.debugger:
> - sa_logger.setLevel(logging.DEBUG)
> - sa_logger.setLevel(logging.DEBUG)
> - sa_logger.addHandler(handler)
> -
> import lnt.server.ui.app
> app = lnt.server.ui.app.App.create_standalone(input_path,)
> + sql_logging = logging.ERROR
> if opts.debugger:
> app.debug = True
> + sql_logging = logging.DEBUG
> +
> + logger, sa_logger = setup_logging(logging.ERROR, sql_logging)
> +
> if opts.profiler:
> app.wsgi_app = werkzeug.contrib.profiler.ProfilerMiddleware(
> app.wsgi_app, stream = open('profiler.log', 'w'))
> @@ -246,19 +254,11 @@ def action_update(name, args):
> db_path, = args
>
> # Setup the base LNT logger.
> - logger = logging.getLogger("lnt")
> - logger.setLevel(logging.INFO)
> - handler = logging.StreamHandler(sys.stderr)
> - handler.setFormatter(logging.Formatter(
> - '%(asctime)s %(levelname)s: %(message)s',
> - datefmt='%Y-%m-%d %H:%M:%S'))
> - logger.addHandler(handler)
> -
> - # Enable full SQL logging, if requested.
> if opts.show_sql:
> - sa_logger = logging.getLogger("sqlalchemy")
> - sa_logger.setLevel(logging.INFO)
> - sa_logger.addHandler(handler)
> + sql_level = logging.INFO
> + else:
> + sql_level = logging.ERROR
> + logger, sa_logger = setup_logging(logging.INFO, sql_level)
>
> # Update the database.
> lnt.server.db.migrate.update_path(db_path)
> @@ -386,15 +386,6 @@ def action_send_run_comparison(name, args):
>
> path, run_a_id, run_b_id = args
>
> - # Setup the base LNT logger.
> - logger = logging.getLogger("lnt")
> - logger.setLevel(logging.ERROR)
> - handler = logging.StreamHandler(sys.stderr)
> - handler.setFormatter(logging.Formatter(
> - '%(asctime)s %(levelname)s: %(message)s',
> - datefmt='%Y-%m-%d %H:%M:%S'))
> - logger.addHandler(handler)
> -
> # Load the LNT instance.
> instance = lnt.server.instance.Instance.frompath(path)
> config = instance.config
>
>
>
>
>
> Chris Matthews
> chris.matthews at apple.com
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131010/5935f9c8/attachment.html>
More information about the llvm-commits
mailing list