diff --git a/main.py b/main.py index c93e312..467c0e3 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ ########################################################## # Third-party imports -from src.athena.server import AthenaServer +from src.rpc.athena.server import AthenaServer if __name__ == '__main__': diff --git a/requirements.txt b/requirements.txt index 957dbdb..357623a 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/athena/__init__.py b/src/rpc/athena/__init__.py similarity index 100% rename from src/athena/__init__.py rename to src/rpc/athena/__init__.py diff --git a/src/athena/client.py b/src/rpc/athena/client.py similarity index 100% rename from src/athena/client.py rename to src/rpc/athena/client.py diff --git a/src/athena/server.py b/src/rpc/athena/server.py similarity index 97% rename from src/athena/server.py rename to src/rpc/athena/server.py index 4fcf42a..c506918 100644 --- a/src/athena/server.py +++ b/src/rpc/athena/server.py @@ -10,7 +10,7 @@ import grpc # Third-party imports -from src.base_server import BaseServer +from src.rpc.base_server import BaseServer from protos.athena import athena_pb2 from protos.athena import athena_pb2_grpc diff --git a/src/base_clienty.py b/src/rpc/base_clienty.py similarity index 100% rename from src/base_clienty.py rename to src/rpc/base_clienty.py diff --git a/src/base_server.py b/src/rpc/base_server.py similarity index 91% rename from src/base_server.py rename to src/rpc/base_server.py index 64683e3..acd978a 100644 --- a/src/base_server.py +++ b/src/rpc/base_server.py @@ -10,6 +10,9 @@ import grpc from concurrent import futures +# Third-party imports +from src.utils import logger + class BaseServer(object): @@ -41,5 +44,6 @@ def start(self) -> None: """ Starts the server in blocking mode. """ + logger.debug(f"Starting server on {self.target}") self.server.start() self.server.wait_for_termination() diff --git a/src/utils/logger.py b/src/utils/logger.py new file mode 100644 index 0000000..0648b10 --- /dev/null +++ b/src/utils/logger.py @@ -0,0 +1,46 @@ +########################################################## +# +# Copyright (C) 2023-PRESENT: Keivan Ipchi Hagh +# +# Email: keivanipchihagh@gmail.com +# GitHub: https://github.com/keivanipchihagh +# +########################################################## + +from colorama import Fore +from pytz import timezone +from datetime import datetime +from colorama import init as colorama_init + +colorama_init() +TZ = timezone('Asia/Tehran') # Timezone + + +def __now() -> str: + """ Returns the current datetime as string """ + return datetime.now(TZ).strftime('%Y-%m-%d %H:%M:%S') + + +def debug(message: str) -> None: + """ Prints a message as debug """ + print(f"[{Fore.MAGENTA}DEBUG{Fore.BLUE} - {Fore.BLACK}{__now()}{Fore.RESET}]\t{message}") + + +def info(message: str) -> None: + """ Prints a message as info """ + print(f"[{Fore.BLUE}INFO{Fore.BLUE} - {Fore.BLACK}{__now()}{Fore.RESET}]\t{message}") + + +def success(message: str) -> None: + """ Prints a message as success """ + print(f"[{Fore.GREEN}SUCCESS{Fore.RESET} - {Fore.BLACK}{__now()}{Fore.RESET}]\t{message}") + + +def error(message: str) -> None: + """ Prints a message as error """ + print(f"[{Fore.RED}ERROR{Fore.RESET} - {Fore.BLACK}{__now()}{Fore.RESET}]\t{message}") + + +def warning(message: str) -> None: + """ Prints a message as warning """ + print(f"[{Fore.YELLOW}WARNING{Fore.RESET} - {Fore.BLACK}{__now()}{Fore.RESET}]\t{message}")