[PATCH][LNT] refactor logging code in main for reuse.
Chris Matthews
chris.matthews at apple.com
Fri Oct 4 10:21:08 PDT 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131004/c4ddf9a1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: refactor_logging.patch
Type: application/octet-stream
Size: 3709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131004/c4ddf9a1/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131004/c4ddf9a1/attachment-0001.html>
More information about the llvm-commits
mailing list