-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.py
45 lines (33 loc) · 1.23 KB
/
log.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
import csv
import datetime
from config import Config
class Log:
def __init__( self, config: Config ):
self.config = config
def write( self, message: str, *args) -> None:
if self.config.LOG_ENABLED is False:
return
with open( self.config.LOG_FILE, 'a', newline='') as file:
writer = csv.writer(file)
now = datetime.datetime.now()
formatted_now = now.strftime('%Y-%m-%d %H:%M:%S')
row = [formatted_now, message]
row.extend(args)
writer.writerow(row)
def started( self ) -> None:
self.write('started', 0 )
def active( self ) -> None:
if self.config.NOTIFY_ACTIVE_LOG:
self.write('internet active', 0 )
def down( self ) -> None:
if self.config.NOTIFY_ACTIVE_LOG:
self.write('internet down', 0 )
def latency( self, latency ) -> None:
if self.config.NOTIFY_LATENCY_LOG:
self.write('latency warning', latency)
def speed_slow( self ) -> None:
if self.config.NOTIFY_LATENCY_LOG:
self.write('speed slow', 0 )
def speed_normal( self ) -> None:
if self.config.NOTIFY_LATENCY_LOG:
self.write('speed normal', 0)