This repository has been archived by the owner on Oct 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
executable file
·65 lines (50 loc) · 1.78 KB
/
logger.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env /usr/local/bin/python3.9
import sys
import os
import logging
from datetime import datetime, date, time
# Initialize logging
homedir = sys.path[0]
logdir = os.path.join(homedir, "logs")
logfilename = "tl.log"
last_image = "last_image.log"
last_shutter = "last_shutter.log"
logfile = os.path.join(logdir, logfilename)
last_image_file = os.path.join(logdir, last_image)
last_shutter_file = os.path.join(logdir, last_shutter)
red = "\033[1;31;38m"
green = "\033[1;32;38m"
endcolor = "\033[0m"
if not os.path.exists(logdir):
os.makedirs(logdir)
print("Made logs/ directory")
logging.basicConfig(filename=logfile, encoding="utf-8", level=logging.DEBUG)
def redText(text):
return red+text+endcolor
def greenText(text):
return green+text+endcolor
def errorMsg(text):
print(red+text+endcolor)
def successMsg(text):
print(green+text+endcolor)
def log(text):
now = datetime.now()
today = str('%02d' % now.day) + "." + str('%02d' % now.month) + "." + str(now.year) + " "
timePrint = today + str('%02d' % now.hour) + ":" + str('%02d' % now.minute) + ":" + str('%02d' % now.second)
logText = greenText("[") + timePrint + greenText("]") + " " + text
logging.info(logText)
print(logText)
def silentlog(text):
now = datetime.now()
today = str('%02d' % now.day) + "." + str('%02d' % now.month) + "." + str(now.year) + " "
timePrint = today + str('%02d' % now.hour) + ":" + str('%02d' % now.minute) + ":" + str('%02d' % now.second)
logText = greenText("[") + timePrint + greenText("]") + " " + text
logging.info(logText)
def loglastfile(filename):
f = open(last_image_file, "w+")
f.write(f"{filename}")
f.close()
def logLastShutterSpeed(shutterspeed):
f = open(last_shutter_file, "w+")
f.write(f"{shutterspeed}")
f.close()