apache_error_stats: Fix to constant and logging

- Fix a bug in the PATTERNS constant, which should be a list of tuples
  instead of a dictionary.
- Change the matching loop to only log that a message is being emitted
  if the .match result is not None.

BUG=chromium:712388
TEST=None

Change-Id: Ic9eb0ddb025006cc89c753f1cc576919aee358c9
Reviewed-on: https://chromium-review.googlesource.com/486121
Commit-Ready: Paul Hobbs <phobbs@google.com>
Tested-by: Paul Hobbs <phobbs@google.com>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
diff --git a/site_utils/stats/apache_error_stats.py b/site_utils/stats/apache_error_stats.py
index 8404ef3..0f5fb7c 100755
--- a/site_utils/stats/apache_error_stats.py
+++ b/site_utils/stats/apache_error_stats.py
@@ -53,9 +53,9 @@
       'mod_wsgi': mod_wsgi_present})
 
 
-MATCHERS = {
-    ERROR_LOG_MATCHER: EmitErrorLogMetric,
-}
+MATCHERS = [
+    (ERROR_LOG_MATCHER, EmitErrorLogMetric),
+]
 
 
 def RunMatchers(stream, matchers):
@@ -70,10 +70,10 @@
     with contextlib.closing(ts_mon):
         for line in iter(stream.readline, ''):
             for matcher, emitter in matchers:
-                logging.debug('Emitting %s for input "%s"',
-                              emitter.__name__, line.strip())
                 m = matcher.match(line)
                 if m:
+                    logging.debug('Emitting %s for input "%s"',
+                                  emitter.__name__, line.strip())
                     emitter(m)