[LNT] r311687 - Remove memory logger in favor of file logger

Chris Matthews via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 24 12:01:09 PDT 2017


Author: cmatthews
Date: Thu Aug 24 12:01:09 2017
New Revision: 311687

URL: http://llvm.org/viewvc/llvm-project?rev=311687&view=rev
Log:
Remove memory logger in favor of file logger

The memory logger has limitations, and is a constant source of bugs.
Remove the memory logger. Make the log page print out the log file
instead.  When running a wsgi server, allow the server to collect logs
from all processes, and use that log file instead.

Modified:
    lnt/trunk/deployment/app_wrapper.py
    lnt/trunk/lnt/server/ui/app.py
    lnt/trunk/lnt/server/ui/templates/log.html
    lnt/trunk/lnt/server/ui/views.py
    lnt/trunk/lnt/util/async_ops.py

Modified: lnt/trunk/deployment/app_wrapper.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/deployment/app_wrapper.py?rev=311687&r1=311686&r2=311687&view=diff
==============================================================================
--- lnt/trunk/deployment/app_wrapper.py (original)
+++ lnt/trunk/deployment/app_wrapper.py Thu Aug 24 12:01:09 2017
@@ -5,4 +5,4 @@ This can be used for deploying on the cl
 
 import lnt.server.ui.app
 
-app = lnt.server.ui.app.App.create_standalone('lnt.cfg')
+app = lnt.server.ui.app.App.create_standalone('lnt.cfg', '/var/log/lnt/lnt.log')

Modified: lnt/trunk/lnt/server/ui/app.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/app.py?rev=311687&r1=311686&r2=311687&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/app.py (original)
+++ lnt/trunk/lnt/server/ui/app.py Thu Aug 24 12:01:09 2017
@@ -32,6 +32,10 @@ from lnt.server.ui.api import load_api_r
 from lnt.util import logger
 
 
+# The default name of the log file.
+LOG_FILENAME = "lnt.log"
+
+
 class RootSlashPatchMiddleware(object):
     def __init__(self, app):
         self.app = app
@@ -200,10 +204,23 @@ class App(LNTExceptionLoggerFlask):
         return app
 
     @staticmethod
-    def create_standalone(config_path):
+    def create_standalone(config_path, log_file=None):
+        """ Create an instance of a lnt Flask application from a config file.
+
+        :param config_path: path to lnt config (directory or config file).
+
+        :param log_file: instead of setting up logging, use this log file.
+        when running in a multiprocess server like gunicorn, you need to use gunicorn's
+        logging instead (since it is multiprocess safe. In this case LNT will print to
+        to stderr and it can be collected by gunicorn. The LNT logs page will show this
+        unified log page.
+
+        :return: a LNT Flask App, ready to be loaded into a wsgi server.
+
+        """
         instance = lnt.server.instance.Instance.frompath(config_path)
         app = App.create_with_instance(instance)
-        app.start_file_logging()
+        app.start_file_logging(log_file)
         return app
 
     def __init__(self, name):
@@ -233,26 +250,20 @@ class App(LNTExceptionLoggerFlask):
 
         lnt.server.db.rules_manager.register_hooks()
 
-    def start_file_logging(self):
+    def start_file_logging(self, log_file_name):
         """Start server production logging.  At this point flask already logs
         to stderr, so just log to a file as well.
 
         """
-        # Print to screen.
+        # Always Print to screen.
         ch = logging.StreamHandler()
-        ch.setLevel(logging.INFO)
+        ch.setLevel(logging.DEBUG)
         self.logger.addHandler(ch)
 
-        # Log to mem for the /log view.
-        h = logging.handlers.MemoryHandler(1024 * 1024,
-                                           flushLevel=logging.CRITICAL)
-        h.setLevel(logging.DEBUG)
-        self.logger.addHandler(h)
-        # Also store the logger, so we can render the buffer in it.
-        self.config['mem_logger'] = h
-
-        if not self.debug:
-            LOG_FILENAME = "lnt.log"
+        # When running in a server config, use the server to setup the log file. If there is more than
+        # one process running, this will not work well.
+        if not self.config.get('log_file_name'):
+            self.config['log_file_name'] = LOG_FILENAME
             try:
                 rotating = logging.handlers.RotatingFileHandler(
                     LOG_FILENAME, maxBytes=1048576, backupCount=5)

Modified: lnt/trunk/lnt/server/ui/templates/log.html
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/templates/log.html?rev=311687&r1=311686&r2=311687&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/templates/log.html (original)
+++ lnt/trunk/lnt/server/ui/templates/log.html Thu Aug 24 12:01:09 2017
@@ -8,42 +8,11 @@
 
 {% block body %}
 
-<table id="logs" class="table">
-  <thead>
-    <tr>
-      <th style="width:130px">Kind</th>
-      <th style="width:130px">Location</th>
-      <th>Message</th>
-    </tr>
-  </thead>
-  <tbody>
-{% for item in config.mem_logger.buffer[::-1] %}
-    {% if item.levelname|string() == 'WARNING' %}
-    <tr class="warning">
-    {% elif item.levelname|string() == 'ERROR' %}
-    <tr class="error">
-    {% else %}
-    <tr class="info">
-    {% endif %}
-      <td>{{ item.levelname}}</td>
-      <td>{{item.filename}}:{{item.lineno}}</td>
-      <td><pre>{{ item.msg }}</pre></td>
-    </tr>
-{% endfor %}
-    </tbody>
-    </table>
-
-
-<script type="text/javascript">
-$(document).ready( function () {
-    var settings = {"dom": '<"top"if>rt<"bottom"Flp>',
-                    "aLengthMenu": [[50, -1],
-                                    [50, "All"]]};
-    dt = $('#logs').DataTable(settings);
-
-});
-
-</script>
+<pre>
+    {% for item in log_lines -%}
+            {{ item -}}
+    {% endfor %}
+</pre>
 
 
 {% endblock %}

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=311687&r1=311686&r2=311687&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Thu Aug 24 12:01:09 2017
@@ -1432,7 +1432,10 @@ def rules():
 @frontend.route('/log')
 def log():
     async_ops.check_workers(True)
-    return render_template("log.html")
+    with open(current_app.config['log_file_name'], 'r') as f:
+        log_lines = f.readlines()
+    r'2017-07-21 15:02:15,143 ERROR:'
+    return render_template("log.html", log_lines=log_lines)
 
 
 @frontend.route('/debug')

Modified: lnt/trunk/lnt/util/async_ops.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/async_ops.py?rev=311687&r1=311686&r2=311687&view=diff
==============================================================================
--- lnt/trunk/lnt/util/async_ops.py (original)
+++ lnt/trunk/lnt/util/async_ops.py Thu Aug 24 12:01:09 2017
@@ -38,16 +38,7 @@ def launch_workers():
     try:
         if not WORKERS:
             logger.info("Starting workers")
-            manager = Manager()
             WORKERS = True
-            try:
-                current_app.config['mem_logger'].buffer = \
-                    manager.list(current_app.config['mem_logger'].buffer)
-            except RuntimeError:
-                #  It might be the case that we are not running in the app.
-                #  In this case, don't bother memory logging, stdout should
-                #  sufficient for console mode.
-                pass
     finally:
         WORKERS_LOCK.release()
 




More information about the llvm-commits mailing list