<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Extract logging code so that it can be called from a few places in main.py.<div><br><div><br></div><div><div>diff --git a/lnt/lnttool/main.py b/lnt/lnttool/main.py</div><div>index 2b667bfb97a67d9316f82908f91773073240cf5c..3fb96e5a4eb4879fcccdf9fc9364c7feea22e620 100644</div><div>--- a/lnt/lnttool/main.py</div><div>+++ b/lnt/lnttool/main.py</div><div>@@ -15,6 +15,27 @@ import lnt.util.ImportData</div><div> from lnt import testing</div><div> from lnt.testing.util.commands import note, warning, error, fatal</div><div> </div><div>+def setup_logging(level=logging.INFO, sql_level=logging.ERROR):</div><div>+ """Setup the LNT loggers.</div><div>+ Arguments: </div><div>+ level - The logging framework level for use in LNT.</div><div>+ show_sql_logging - Logging level for sqlAlchmey.</div><div>+ """</div><div>+ logger = logging.getLogger("lnt")</div><div>+ logger.setLevel(level)</div><div>+ handler = logging.StreamHandler(sys.stderr)</div><div>+ handler.setFormatter(logging.Formatter(</div><div>+ '%(asctime)s %(levelname)s: %(message)s',</div><div>+ datefmt='%Y-%m-%d %H:%M:%S'))</div><div>+ logger.addHandler(handler)</div><div>+</div><div>+ # Enable full SQL logging, if requested.</div><div>+ sa_logger = logging.getLogger("sqlalchemy")</div><div>+ sa_logger.setLevel(sql_level)</div><div>+ sa_logger.addHandler(handler)</div><div>+</div><div>+ return logger, sa_logger</div><div>+</div><div> def action_runserver(name, args):</div><div> """start a new development server"""</div><div> </div><div>@@ -56,28 +77,15 @@ view the results.\</div><div> </div><div> input_path, = args</div><div> </div><div>- # Setup the base LNT logger.</div><div>- logger = logging.getLogger("lnt")</div><div>- if opts.debugger:</div><div>- logger.setLevel(logging.DEBUG)</div><div>- handler = logging.StreamHandler(sys.stderr)</div><div>- handler.setFormatter(logging.Formatter(</div><div>- '%(asctime)s %(levelname)s: %(message)s',</div><div>- datefmt='%Y-%m-%d %H:%M:%S'))</div><div>- logger.addHandler(handler)</div><div>-</div><div>- # Enable full SQL logging, if requested.</div><div>- if opts.show_sql:</div><div>- sa_logger = logging.getLogger("sqlalchemy")</div><div>- if opts.debugger:</div><div>- sa_logger.setLevel(logging.DEBUG)</div><div>- sa_logger.setLevel(logging.DEBUG)</div><div>- sa_logger.addHandler(handler)</div><div>-</div><div> import lnt.server.ui.app</div><div> app = lnt.server.ui.app.App.create_standalone(input_path,)</div><div>+ sql_logging = logging.ERROR</div><div> if opts.debugger:</div><div> app.debug = True</div><div>+ sql_logging = logging.DEBUG</div><div>+ </div><div>+ logger, sa_logger = setup_logging(logging.ERROR, sql_logging) </div><div>+ </div><div> if opts.profiler:</div><div> app.wsgi_app = werkzeug.contrib.profiler.ProfilerMiddleware(</div><div> app.wsgi_app, stream = open('profiler.log', 'w'))</div><div>@@ -246,19 +254,11 @@ def action_update(name, args):</div><div> db_path, = args</div><div> </div><div> # Setup the base LNT logger.</div><div>- logger = logging.getLogger("lnt")</div><div>- logger.setLevel(logging.INFO)</div><div>- handler = logging.StreamHandler(sys.stderr)</div><div>- handler.setFormatter(logging.Formatter(</div><div>- '%(asctime)s %(levelname)s: %(message)s',</div><div>- datefmt='%Y-%m-%d %H:%M:%S'))</div><div>- logger.addHandler(handler)</div><div>-</div><div>- # Enable full SQL logging, if requested.</div><div> if opts.show_sql:</div><div>- sa_logger = logging.getLogger("sqlalchemy")</div><div>- sa_logger.setLevel(logging.INFO)</div><div>- sa_logger.addHandler(handler)</div><div>+ sql_level = logging.INFO</div><div>+ else:</div><div>+ sql_level = logging.ERROR</div><div>+ logger, sa_logger = setup_logging(logging.INFO, sql_level)</div><div> </div><div> # Update the database.</div><div> lnt.server.db.migrate.update_path(db_path)</div><div>@@ -386,15 +386,6 @@ def action_send_run_comparison(name, args):</div><div> </div><div> path, run_a_id, run_b_id = args</div><div> </div><div>- # Setup the base LNT logger.</div><div>- logger = logging.getLogger("lnt")</div><div>- logger.setLevel(logging.ERROR)</div><div>- handler = logging.StreamHandler(sys.stderr)</div><div>- handler.setFormatter(logging.Formatter(</div><div>- '%(asctime)s %(levelname)s: %(message)s',</div><div>- datefmt='%Y-%m-%d %H:%M:%S'))</div><div>- logger.addHandler(handler)</div><div>-</div><div> # Load the LNT instance.</div><div> instance = lnt.server.instance.Instance.frompath(path)</div><div> config = instance.config</div></div><div><br></div><div><br></div><div></div></div></body></html>