+ while 0 < len(universe.loglines) >= max_log_lines: del universe.loglines[0]
+ universe.loglines.append((level, timestamp + " " + line))
+
+def get_loglines(level, start, stop=0):
+ """Return a specific range of loglines filtered by level."""
+
+ # begin with a blank message
+ message = ""
+
+ # filter the log lines
+ loglines = filter(lambda x,y: x>=level, universe.loglines)
+
+ # we need this in several places
+ count = len(loglines)
+
+ # don't proceed if there are no lines
+ if count:
+
+ # can't start before the begining or at the end
+ if start > count: start = count
+ if start < 1: start = 1
+
+ # can't stop before we start
+ if stop >= start: stop = start - 1
+
+ # some preamble
+ message += "There are " + str(len(universe.loglist))
+ message += " log lines in memory and " + str(count)
+ message += " at or above level " + str(level) + "."
+ message += " The lines from " + str(stop)
+ message += " to " + str(start) + " are:$(eol)$(eol)"
+
+ # add the text from the selected lines
+ for line in loglines[-start:-stop]:
+ message += " " + line[1] + "$(eol)"
+
+ # pass it back
+ return message