-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.py
More file actions
32 lines (25 loc) · 714 Bytes
/
log.py
File metadata and controls
32 lines (25 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from datetime import datetime
import bash
import jobs
LOG_FILE = "log"
indent = 0
def _write(msg):
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
msg = "%s %s%s" % (now, " " * indent * 4, msg)
msg = msg.replace("\n", "\n" + (" " * (4 + len(now) + indent * 4)))
print msg
with open(LOG_FILE, "a") as log_file:
log_file.write(msg + "\n")
def debug(msg, extra_indent=0):
global indent
indent += extra_indent
_write(msg)
indent -= extra_indent
def info(msg, extra_indent=0):
jobs.append_log(msg)
debug(msg, extra_indent)
error = debug
warning = debug
def get_lines(n):
r = bash.execute_inner("tail -n %s %s" % (n, LOG_FILE))
return r["stdout"]