aboutsummaryrefslogtreecommitdiff
path: root/log.py
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-09-28 19:30:41 +0200
committerneodarz <neodarz@neodarz.net>2019-09-28 19:30:41 +0200
commitd70390197ee3e06ee1fecbc14d1ed48ba4040c94 (patch)
tree325267c8d64ed2d7282d1d3166b0a651b9594ddc /log.py
downloadpykeepalive-d70390197ee3e06ee1fecbc14d1ed48ba4040c94.tar.xz
pykeepalive-d70390197ee3e06ee1fecbc14d1ed48ba4040c94.zip
Initial commitHEADmaster
Diffstat (limited to 'log.py')
-rw-r--r--log.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/log.py b/log.py
new file mode 100644
index 0000000..a4ff80c
--- /dev/null
+++ b/log.py
@@ -0,0 +1,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))