From 241d4acfa635b1dc991ce6cbcc832fdb836e678e Mon Sep 17 00:00:00 2001
From: Andreas Thielen <thielen@adesso-mobile.de>
Date: Thu, 1 Aug 2013 11:59:19 +0200
Subject: [PATCH] Checking if format is not nil before logging

---
 misc/log-analytics/import_logs.py | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/misc/log-analytics/import_logs.py b/misc/log-analytics/import_logs.py
index c8bbbb4e6e..5869a2bd87 100755
--- a/misc/log-analytics/import_logs.py
+++ b/misc/log-analytics/import_logs.py
@@ -116,7 +116,7 @@ class RegexFormat(object):
         line = file.readline()
         file.seek(0)
         return self.check_format_line(line)
-    
+
     def check_format_line(self, line):
         return re.match(self.regex, line)
 
@@ -158,7 +158,7 @@ class IisFormat(RegexFormat):
                 regex = '\S+'
             full_regex.append(regex)
         self.regex = re.compile(' '.join(full_regex))
-        
+
         start_pos = file.tell()
         nextline = file.readline()
         file.seek(start_pos)
@@ -875,7 +875,7 @@ class StaticResolver(object):
             site = sites[0]
         except (IndexError, KeyError):
             logging.debug('response for SitesManager.getSiteFromId: %s', str(sites))
-            
+
             fatal_error(
                 "cannot get the main URL of this site: invalid site ID: %s" % site_id
             )
@@ -976,7 +976,7 @@ class DynamicResolver(object):
             return (site_id, self._cache['sites'][site_id]['main_url'])
         else:
             return (None, None)
-    
+
     def _resolve_by_host(self, hit):
         """
         Returns the site ID and site URL for a hit based on the hostname.
@@ -1131,7 +1131,7 @@ class Recorder(object):
         path = hit.path
         if hit.query_string and not config.options.strip_query_string:
             path += config.options.query_string_delimiter + hit.query_string
-        
+
         # only prepend main url if it's a path
         url = (main_url if path.startswith('/') else '') + path[:1024]
 
@@ -1237,7 +1237,7 @@ class Hit(object):
         for key, value in kwargs.iteritems():
             setattr(self, key, value)
         super(Hit, self).__init__()
-        
+
         if config.options.force_lowercase_path:
             self.full_path = self.full_path.lower()
 
@@ -1333,14 +1333,14 @@ class Parser(object):
         Return the best matching format for this file, or None if none was found.
         """
         logging.debug('Detecting the log format')
-        
+
         format = None
         format_groups = 0
         for name, candidate_format in FORMATS.iteritems():
             match = candidate_format.check_format(file)
             if match:
                 logging.debug('Format %s matches', name)
-                
+
                 # if there's more info in this match, use this format
                 match_groups = len(match.groups())
                 if format_groups < match_groups:
@@ -1348,8 +1348,10 @@ class Parser(object):
                     format_groups = match_groups
             else:
                 logging.debug('Format %s does not match', name)
-        
-        logging.debug('Format %s is the best match', format.name)
+
+        if format:
+            logging.debug('Format %s is the best match', format.name)
+
         return format
 
     def parse(self, filename):
-- 
GitLab