aboutsummaryrefslogtreecommitdiff
path: root/log.py
blob: a4ff80ca6a5749ad8c5b82bfd2adeea241986064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#/bin/python3

import platform
import subprocess

from config import *
import commands

def tail_log():
    if commands.file_len(LOG_PATH_FILE) > LINES_MAX:
        if platform.system().lower()=='windows':
            datas = commands.tail(LOG_PATH_FILE, LINES_MIN)
            with open(LOG_PATH_FILE, "wb") as f:
                f.write(b' \n'.join(datas))
        else:
            command = ["tail", "-"+str(LINES_MIN), str(LOG_PATH_FILE)]
            proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            datas = proc.stdout.decode('utf-8')
            with open(LOG_PATH_FILE, "w") as f:
                f.write("".join(datas))