-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathensemble_logging.py
More file actions
36 lines (27 loc) · 1.02 KB
/
Copy pathensemble_logging.py
File metadata and controls
36 lines (27 loc) · 1.02 KB
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
33
34
35
36
#!/usr/bin/python3
import os
import sys
import ensemble_constants
from datetime import datetime
logLevel = 1
logConsumer = ensemble_constants.DIRECTOR_LOG_FILENAME
def initialize(consumer):
global logConsumer
logConsumer = consumer
def log_message(text):
timeStamp = get_date_time_now()
if(logLevel == 1):
os.popen(f"{ensemble_constants.ECHO_COMMAND} '{timeStamp}: {text}' >> {ensemble_constants.LOGS_DIR}/{logConsumer}")
elif(logLevel == 2):
print(f"{timeStamp}: {text}", file=sys.stdout)
def log_job(job):
jobString = ""
jobString += f"Job ID: {job['Id']}"
jobString += f"Job CMD: {job['Cmd']}"
jobString += f"Job Targets: {job['Targets']}"
jobString += f"Job Run In Single Command: {job['IsSingleCmd']}"
log_message(jobString)
def log_job_completed(job):
log_message(f"Job Completed: {job['Id']}")
def get_date_time_now():
return datetime.fromtimestamp(datetime.now().timestamp())