-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
28 lines (17 loc) · 654 Bytes
/
Copy pathlogger.py
File metadata and controls
28 lines (17 loc) · 654 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
import sys
from datetime import datetime
file_name = sys.argv[1].rstrip()
log_file = open(f"{file_name}", "a")
# Function formats the datetime, action, and message
def format_action_message(action, message):
return f"{datetime.now().strftime('%Y-%m-%d %H:%M')} [{action}] {message}.\n"
# write the START action
log_file.write(format_action_message("START", "Logging Started"))
while True:
line = sys.stdin.readline().rstrip()
action = line[:line.index(' ')]
message = line[line.index(' ') + 1:]
log_file.write(format_action_message(action, message))
if action == "STOPPED":
log_file.close()
sys.exit(0)