-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
208109e
commit ef9c395
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import logging | ||
import signal | ||
|
||
NGINX = "NGINX" | ||
HTTPD = "HTTPD" | ||
PROXY = "PROXY" | ||
|
||
PORT = { | ||
NGINX: "8009", | ||
HTTPD: "8008", | ||
PROXY: "80" | ||
} | ||
|
||
# Logger configuration | ||
logging.basicConfig( | ||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' | ||
) | ||
|
||
# Get a specific logger for the package | ||
logger = logging.getLogger('MASS') | ||
|
||
def configure_logging(level=logging.INFO): | ||
logger.setLevel(level) | ||
for handler in logger.handlers: | ||
handler.setLevel(level) | ||
|
||
_shutdown = False | ||
|
||
def get_shutdown(): | ||
return _shutdown | ||
|
||
|
||
def signal_handler(sig, frame): | ||
global _shutdown | ||
if not _shutdown: | ||
logger.info("\nShutting down...") | ||
_shutdown = True | ||
|
||
signal.signal(signal.SIGINT, signal_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import time | ||
import functools | ||
from .config import logger | ||
|
||
def timing_decorator(func): | ||
@functools.wraps(func) | ||
def wrapper(*args, **kwargs): | ||
start_time = time.time() | ||
result = func(*args, **kwargs) | ||
end_time = time.time() | ||
elapsed_time = end_time - start_time | ||
logger.debug(f"Method {func.__name__} execution took: {elapsed_time:.6f} seconds.") | ||
return result | ||
return wrapper | ||
|
||
def apply_timing_to_methods(decorator): | ||
def decorate(cls): | ||
for attr in dir(cls): | ||
if attr.startswith("__") and attr.endswith("__"): | ||
continue | ||
original_method = getattr(cls, attr) | ||
if callable(original_method): | ||
decorated_method = decorator(original_method) | ||
setattr(cls, attr, decorated_method) | ||
return cls | ||
return decorate |