comparison web/log.py @ 409:1854abee5a59

add debug url
author Matt Johnston <matt@ucc.asn.au>
date Thu, 02 Aug 2012 22:11:13 +0800
parents 36a33c56c383
children 7f3fc0980df1
comparison
equal deleted inserted replaced
408:88f578f36bde 409:1854abee5a59
146 146
147 # be paranoid 147 # be paranoid
148 f = file(rrdfile) 148 f = file(rrdfile)
149 os.fsync(f.fileno()) 149 os.fsync(f.fileno())
150 150
151 def debug_file(mode='r'):
152 return open('%s/debug.log' % config.DATA_PATH, mode)
153
151 def record_debug(lines): 154 def record_debug(lines):
152 f = open('%s/debug.log' % config.DATA_PATH, 'a+') 155 f = debug_file('a+')
153 f.write('===== %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S')) 156 f.write('===== %s =====\n' % time.strftime('%a, %d %b %Y %H:%M:%S'))
154 f.writelines(('%s\n' % s for s in lines)) 157 f.writelines(('%s\n' % s for s in lines))
155 f.flush() 158 f.flush()
156 return f 159 return f
160
161
162 def tail_debug_log():
163 f = debug_file()
164 f.seek(0, 2)
165 size = f.tell()
166 f.seek(max(0, size-30000))
167 return '\n'.join(l.strip() for l in f.readlines()[-400:])
157 168
158 def convert_ds18b20_12bit(reading): 169 def convert_ds18b20_12bit(reading):
159 value = struct.unpack('>h', binascii.unhexlify(reading))[0] 170 value = struct.unpack('>h', binascii.unhexlify(reading))[0]
160 return value * 0.0625 171 return value * 0.0625
161 172