Add timestamps to the log output.
This commit is contained in:
@@ -23,6 +23,7 @@ import struct
|
|||||||
import sys
|
import sys
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.prompt import Prompt
|
from rich.prompt import Prompt
|
||||||
|
from notification_producer.timestamp import Timestamp
|
||||||
|
|
||||||
|
|
||||||
class ProducerClient:
|
class ProducerClient:
|
||||||
@@ -38,9 +39,11 @@ class ProducerClient:
|
|||||||
async def connect(self):
|
async def connect(self):
|
||||||
try:
|
try:
|
||||||
self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port)
|
self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port)
|
||||||
self.console.print(f'[yellow b][INFO][/] Connected to the server ({self.__ip}:{self.__port}).')
|
now = Timestamp.now()
|
||||||
|
self.console.print(f'[yellow b][INFO][/][#8abeb7 b][{now}][/] Connected to the server ({self.__ip}:{self.__port}).')
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
sys.stderr.write("Could not connect to the server. Please, check the ip and the port.\n")
|
now = Timestamp.now()
|
||||||
|
sys.stderr.write(f"[ERROR][{now}] Could not connect to the server. Please, check the ip and the port.\n")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
async def send(self, message: str):
|
async def send(self, message: str):
|
||||||
@@ -63,7 +66,8 @@ class ProducerClient:
|
|||||||
await self.send_notification(title, message)
|
await self.send_notification(title, message)
|
||||||
|
|
||||||
if title == '' and message == '':
|
if title == '' and message == '':
|
||||||
self.console.print(f"[yellow b][INFO][/] Finished.")
|
now = Timestamp.now()
|
||||||
|
self.console.print(f"[yellow b][INFO][/][#8abeb7 b][{now}][/] Finished.")
|
||||||
self.console.print("[green]bye[/]")
|
self.console.print("[green]bye[/]")
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -71,6 +75,8 @@ class ProducerClient:
|
|||||||
pass
|
pass
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
await self.send_notification('', '')
|
await self.send_notification('', '')
|
||||||
|
now = Timestamp.now()
|
||||||
|
self.console.print(f"[yellow b][INFO][/][#8abeb7 b][{now}][/] Finished.")
|
||||||
self.console.print("\n[green]bye[/]")
|
self.console.print("\n[green]bye[/]")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class Timestamp:
|
||||||
|
@staticmethod
|
||||||
|
def now() -> str:
|
||||||
|
return str(datetime.now())
|
||||||
|
|
||||||
Reference in New Issue
Block a user