diff web/log.py @ 103:ef59da811986

add debug url
author Matt Johnston <matt@ucc.asn.au>
date Thu, 02 Aug 2012 22:11:13 +0800
parents fd8482365489
children 7f3fc0980df1
line wrap: on
line diff
--- a/web/log.py	Wed Jul 25 23:03:34 2012 +0800
+++ b/web/log.py	Thu Aug 02 22:11:13 2012 +0800
@@ -148,13 +148,24 @@
         f = file(rrdfile)
         os.fsync(f.fileno())
 
+def debug_file(mode='r'):
+    return open('%s/debug.log' % config.DATA_PATH, mode)
+
 def record_debug(lines):
-    f = open('%s/debug.log' % config.DATA_PATH, 'a+')
+    f = debug_file('a+')
     f.write('===== %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S'))
     f.writelines(('%s\n' % s for s in lines))
     f.flush()
     return f
 
+
+def tail_debug_log():
+    f = debug_file()
+    f.seek(0, 2)
+    size = f.tell()
+    f.seek(max(0, size-30000))
+    return '\n'.join(l.strip() for l in f.readlines()[-400:])
+
 def convert_ds18b20_12bit(reading):
     value = struct.unpack('>h', binascii.unhexlify(reading))[0]
     return value * 0.0625