<div dir="ltr">Thanks, comments:<div><br></div><div>#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).</div><div><br></div><div>
#2. Doesn't this patch remove the logger from send-run-comparison?</div><div><br></div><div>#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.</div>
<div><br></div><div> - Daniel</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Oct 4, 2013 at 10:21 AM, Chris Matthews <span dir="ltr"><<a href="mailto:chris.matthews@apple.com" target="_blank">chris.matthews@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">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></div><br><div style="word-wrap:break-word"><div><div><br><div>
<div style="text-indent:0px;letter-spacing:normal;text-align:start;text-transform:none;white-space:normal;word-wrap:break-word;word-spacing:0px"><div style="text-indent:0px;letter-spacing:normal;text-align:start;text-transform:none;white-space:normal;word-wrap:break-word;word-spacing:0px">
<div style="text-indent:0px;letter-spacing:normal;text-align:start;text-transform:none;white-space:normal;word-wrap:break-word;word-spacing:0px"><div style="text-indent:0px;letter-spacing:normal;text-align:start;text-transform:none;white-space:normal;word-wrap:break-word;word-spacing:0px">
<br><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:start;font-style:normal;display:inline!important;font-weight:normal;float:none;line-height:normal;text-transform:none;white-space:normal;font-family:Helvetica;word-spacing:0px">Chris Matthews</span><br style="line-height:normal;text-indent:0px;letter-spacing:normal;text-align:start;font-variant:normal;text-transform:none;font-style:normal;white-space:normal;font-family:Helvetica;font-weight:normal;word-spacing:0px">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:start;font-style:normal;display:inline!important;font-weight:normal;float:none;line-height:normal;text-transform:none;white-space:normal;font-family:Helvetica;word-spacing:0px"><a href="mailto:chris.matthews@apple.com" target="_blank">chris.matthews@apple.com</a></span><br style="line-height:normal;text-indent:0px;letter-spacing:normal;text-align:start;font-variant:normal;text-transform:none;font-style:normal;white-space:normal;font-family:Helvetica;font-weight:normal;word-spacing:0px">
</div></div></div></div>
</div>
<br></div></div></div><br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>