Browse Source

Fix a bug : user remove log subdirectory at runtime



git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac176@2142 e5f2f494-b856-4b98-b285-d166d9295462
Jerry 15 years ago
parent
commit
e818104708

+ 2 - 2
src/bin/xfrout/xfrout.spec.pre.in

@@ -12,7 +12,7 @@
          "item_name": "db_file",
          "item_name": "db_file",
          "item_type": "string",
          "item_type": "string",
          "item_optional": False,
          "item_optional": False,
-         "item_default": '@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3'
+         "item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3"
        },
        },
        {
        {
          "item_name": "log_name",
          "item_name": "log_name",
@@ -24,7 +24,7 @@
          "item_name": "log_file",
          "item_name": "log_file",
     	 "item_type": "string",
     	 "item_type": "string",
          "item_optional": False,
          "item_optional": False,
-         "item_default": '@@LOCALSTATEDIR@@/@PACKAGE@/log/Xfrout.log'
+         "item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/log/Xfrout.log"
        },
        },
        {
        {
          "item_name": "log_severity",
          "item_name": "log_severity",

+ 4 - 0
src/lib/python/isc/log/log.py

@@ -54,6 +54,9 @@ class NSFileLogHandler(logging.handlers.RotatingFileHandler):
         dfn = self.baseFilename                 
         dfn = self.baseFilename                 
         if (self.stream) and (not os.path.exists(dfn)): #Is log file exist?
         if (self.stream) and (not os.path.exists(dfn)): #Is log file exist?
             self.stream.close()
             self.stream.close()
+            dir = os.path.split(dfn)
+            if not (os.path.exists(dir[0])): #Is log subdirectory exist?
+                os.makedirs(dir[0])
             self.stream = self._open()
             self.stream = self._open()
         return super(NSFileLogHandler, self).shouldRollover(record)
         return super(NSFileLogHandler, self).shouldRollover(record)
     
     
@@ -72,6 +75,7 @@ class NSFileLogHandler(logging.handlers.RotatingFileHandler):
         self.maxBytes = max_bytes
         self.maxBytes = max_bytes
         self.backupCount = backup_count
         self.backupCount = backup_count
 
 
+
 class NSSysLogHandler(logging.Handler):    
 class NSSysLogHandler(logging.Handler):    
     """Replace SysLogHandler with a custom handler 
     """Replace SysLogHandler with a custom handler 
 
 

+ 3 - 2
src/lib/python/isc/log/tests/log_test.py

@@ -1,7 +1,6 @@
 from isc.log.log import *
 from isc.log.log import *
 import unittest
 import unittest
 import os
 import os
-import sys
 import tempfile
 import tempfile
 
 
 
 
@@ -38,9 +37,11 @@ class TestRotateFileHandler(unittest.TestCase):
 
 
     def tearDown(self):
     def tearDown(self):
         os.close(self.FILE_LOG1[0])
         os.close(self.FILE_LOG1[0])
-        os.close(self.FILE_LOG2[0])
         os.unlink(self.FILE_LOG1[1])
         os.unlink(self.FILE_LOG1[1])
+        os.close(self.FILE_LOG2[0])
         os.unlink(self.FILE_LOG2[1])
         os.unlink(self.FILE_LOG2[1])
+        os.close(self.FILE_LOG3[0])
+        os.unlink(self.FILE_LOG3[1])
         self.handler.flush()
         self.handler.flush()
         self.handler.close()
         self.handler.close()