[CalendarServer-changes] [8261] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Nov 8 10:46:22 PST 2011
Revision: 8261
http://trac.macosforge.org/projects/calendarserver/changeset/8261
Author: sagen at apple.com
Date: 2011-11-08 10:46:21 -0800 (Tue, 08 Nov 2011)
Log Message:
-----------
Fixes the long-line truncation logic for error.log
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/caldav.py
CalendarServer/trunk/calendarserver/tap/test/longlines.py
CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
CalendarServer/trunk/twistedcaldav/upgrade.py
Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py 2011-11-08 15:01:48 UTC (rev 8260)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py 2011-11-08 18:46:21 UTC (rev 8261)
@@ -1635,6 +1635,7 @@
"""
MAX_LENGTH = 1024
+ CONTINUED_TEXT = " (truncated, continued)"
tag = None
exceeded = False # Am I in the middle of parsing a long line?
_buffer = ''
@@ -1675,10 +1676,29 @@
A very long line is being received. Log it immediately and forget
about buffering it.
"""
- for i in range(len(line)/self.MAX_LENGTH):
- self.lineReceived(line[i*self.MAX_LENGTH:(i+1)*self.MAX_LENGTH]
- + " (truncated, continued)")
+ segments = self._breakLineIntoSegments(line)
+ for segment in segments:
+ self.lineReceived(segment)
+
+ def _breakLineIntoSegments(self, line):
+ """
+ Break a line into segments no longer than self.MAX_LENGTH. Each
+ segment (except for the final one) has self.CONTINUED_TEXT appended.
+ Returns the array of segments.
+ @param line: The line to break up
+ @type line: C{str}
+ @return: array of C{str}
+ """
+ length = len(line)
+ numSegments = length/self.MAX_LENGTH + (1 if length%self.MAX_LENGTH else 0)
+ segments = []
+ for i in range(numSegments):
+ msg = line[i*self.MAX_LENGTH:(i+1)*self.MAX_LENGTH]
+ if i < numSegments - 1: # not the last segment
+ msg += self.CONTINUED_TEXT
+ segments.append(msg)
+ return segments
class DelayedStartupLoggingProtocol(ProcessProtocol):
Modified: CalendarServer/trunk/calendarserver/tap/test/longlines.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/test/longlines.py 2011-11-08 15:01:48 UTC (rev 8260)
+++ CalendarServer/trunk/calendarserver/tap/test/longlines.py 2011-11-08 18:46:21 UTC (rev 8261)
@@ -19,7 +19,7 @@
length = int(sys.argv[1])
data = (("x" * length) +
- ("y" * length) + "\n" +
+ ("y" * (length + 1)) + "\n" +
("z" + "\n"))
sys.stdout.write(data)
Modified: CalendarServer/trunk/calendarserver/tap/test/test_caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2011-11-08 15:01:48 UTC (rev 8260)
+++ CalendarServer/trunk/calendarserver/tap/test/test_caldav.py 2011-11-08 18:46:21 UTC (rev 8261)
@@ -1031,11 +1031,13 @@
def assertions(result):
self.assertEquals(["[Dummy] x",
"[Dummy] y",
+ "[Dummy] y", # final segment
"[Dummy] z"],
[''.join(evt['message'])[:len('[Dummy]') + 2]
for evt in logged])
self.assertEquals([" (truncated, continued)",
" (truncated, continued)",
+ "[Dummy] y",
"[Dummy] z"],
[''.join(evt['message'])[-len(" (truncated, continued)"):]
for evt in logged])
@@ -1043,6 +1045,36 @@
return d
+ def test_breakLineIntoSegments(self):
+ """
+ Exercise the line-breaking logic with various key lengths
+ """
+ testLogger = DelayedStartupLineLogger()
+ testLogger.MAX_LENGTH = 10
+ for input, output in [
+ ("", []),
+ ("a", ["a"]),
+ ("abcde", ["abcde"]),
+ ("abcdefghij", ["abcdefghij"]),
+ ("abcdefghijk",
+ ["abcdefghij (truncated, continued)",
+ "k"
+ ]
+ ),
+ ("abcdefghijklmnopqrst",
+ ["abcdefghij (truncated, continued)",
+ "klmnopqrst"
+ ]
+ ),
+ ("abcdefghijklmnopqrstuv",
+ ["abcdefghij (truncated, continued)",
+ "klmnopqrst (truncated, continued)",
+ "uv"]
+ ),
+ ]:
+ self.assertEquals(output, testLogger._breakLineIntoSegments(input))
+
+
def test_acceptDescriptorInheritance(self):
"""
If a L{TwistdSlaveProcess} specifies some file descriptors to be
Modified: CalendarServer/trunk/twistedcaldav/upgrade.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/upgrade.py 2011-11-08 15:01:48 UTC (rev 8260)
+++ CalendarServer/trunk/twistedcaldav/upgrade.py 2011-11-08 18:46:21 UTC (rev 8261)
@@ -584,7 +584,7 @@
if os.path.exists(triggerPath):
os.remove(triggerPath)
- log.info("Migrating locations and resources")
+ log.warn("Migrating locations and resources")
directory = getDirectory()
userService = directory.serviceForRecordType("users")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20111108/bb8ddbd5/attachment.html>
More information about the calendarserver-changes
mailing list