changeset 409:1854abee5a59

add debug url
author Matt Johnston <matt@ucc.asn.au>
date Thu, 02 Aug 2012 22:11:13 +0800
parents 88f578f36bde
children 910324f14fe4
files web/log.py web/templog.py
diffstat 2 files changed, 16 insertions(+), 11 deletions(-) [+]
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
--- a/web/templog.py	Wed Jul 25 23:03:34 2012 +0800
+++ b/web/templog.py	Thu Aug 02 22:11:13 2012 +0800
@@ -79,16 +79,10 @@
                     end = end.strftime(DATE_FORMAT),
                     length = minutes)
 
-@route('/test')
-def test():
-    import config
-    import os
-    f = open('%s/testout' % config.DATA_PATH, 'a+')
-    f.write("more")
-    f.flush()
-    f.close()
-
-    return 'done'
+@route('/debug')
+def debuglog():
+    response.set_header('Content-Type', 'text/plain')
+    return log.tail_debug_log()
 
 def main():
     #bottle.debug(True)