Commit e8181047 authored by Jerry's avatar Jerry
Browse files

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
parent 17bd03fe
......@@ -12,7 +12,7 @@
"item_name": "db_file",
"item_type": "string",
"item_optional": False,
"item_default": '@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3'
"item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/zone.sqlite3"
},
{
"item_name": "log_name",
......@@ -24,7 +24,7 @@
"item_name": "log_file",
"item_type": "string",
"item_optional": False,
"item_default": '@@LOCALSTATEDIR@@/@PACKAGE@/log/Xfrout.log'
"item_default": "@@LOCALSTATEDIR@@/@PACKAGE@/log/Xfrout.log"
},
{
"item_name": "log_severity",
......
......@@ -54,6 +54,9 @@ class NSFileLogHandler(logging.handlers.RotatingFileHandler):
dfn = self.baseFilename
if (self.stream) and (not os.path.exists(dfn)): #Is log file exist?
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()
return super(NSFileLogHandler, self).shouldRollover(record)
......@@ -72,6 +75,7 @@ class NSFileLogHandler(logging.handlers.RotatingFileHandler):
self.maxBytes = max_bytes
self.backupCount = backup_count
class NSSysLogHandler(logging.Handler):
"""Replace SysLogHandler with a custom handler
......
from isc.log.log import *
import unittest
import os
import sys
import tempfile
......@@ -38,9 +37,11 @@ class TestRotateFileHandler(unittest.TestCase):
def tearDown(self):
os.close(self.FILE_LOG1[0])
os.close(self.FILE_LOG2[0])
os.unlink(self.FILE_LOG1[1])
os.close(self.FILE_LOG2[0])
os.unlink(self.FILE_LOG2[1])
os.close(self.FILE_LOG3[0])
os.unlink(self.FILE_LOG3[1])
self.handler.flush()
self.handler.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment