OSDN Git Service

commited
[karesansui/karesansui.git] / karesansui / lib / log / viewer.py
index 000de7a..6838ac6 100644 (file)
@@ -16,6 +16,7 @@
 import re
 import time
 import os
+import os.path
 import sha
 import gzip
 
@@ -26,7 +27,11 @@ def read_all_log(app_log_config, max_line, start_datetime="", end_datetime="", k
     
     for log in app_log_config['logs']:
         log_path = "/var/log/%s/%s" % (log["dir"], log["filename"])
+        if os.path.isfile(log_path) is False:
+            return False
         lines = read_log(log_path, max_line, log, start_datetime, end_datetime, keyword)
+        if lines is False:
+            return False
         for line in lines:
             key = sha.new(line).hexdigest()
             logs.update({key: line})
@@ -60,6 +65,8 @@ def read_log_with_lotate(filename, max_line, log_config, start_datetime="", end_
     lines = []
     for read_filename in log_dir_list:
         log_path = "%s/%s" % (log_dir, read_filename)
+        if os.path.isfile(log_path) is False:
+            return False
         lines += read_log(log_path, max_line, log_config, start_datetime, end_datetime, keyword)
         if len(lines) >= max_line:
             return lines[:max_line]
@@ -81,6 +88,9 @@ def is_gzip(fd):
         return 0
 
 def read_log(path, max_line, log_config, start_datetime="", end_datetime="", keyword=""):
+    if os.path.isfile(path) is False:
+        return False
+
     try:
         fd = open(path, "r")
     except Exception,e: