log_rotate script added

master
Stefan Krulj 14 years ago
parent 8f4dcaa4c9
commit 9d8f7c2ba1
  1. 28
      log_rotate.py

@ -0,0 +1,28 @@
#!/usr/bin/python
import os,sys
import time,datetime
LOG_FILE = "./brathuhn.log"
ROT_SIZE = 2**20
ROT_CRITICAL = 2**20+50*2**10
f = open(LOG_FILE,'wb')
cnt = 0
c = sys.stdin.read(1)
while c!='':
f.write(c)
cnt+=1
if c=='\n' and cnt>=ROT_SIZE or cnt>=ROT_CRITICAL:
f.close()
os.rename(LOG_FILE, LOG_FILE+date.strftime("_%Y-%m-%d_%H-%M-%S") )
f = open(LOG_FILE,'wb')
date=datetime.datetime.fromtimestamp(time.time())
print "rotate",cnt,date.strftime("%Y-%m-%d %H:%M:%S")
cnt = 0
c = sys.stdin.read(1)
Loading…
Cancel
Save