ensure that we can call the new api.fc.archgw.com url, logging fixes … (#142)

* ensure that we can call the new api.fc.archgw.com url, logging fixes and minor cli bug fixes

* fixed a bug where model_server printed on terminal after start script stopped running

* updating the logo and fixing the website styles

* updated the branch with feedback from Co and Adil

---------

Co-authored-by: Salman Paracha <salmanparacha@MacBook-Pro-261.local>
This commit is contained in:
Salman Paracha 2024-10-08 12:40:24 -07:00 committed by GitHub
parent 82fc91495e
commit 3ed50e61d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 70 additions and 47 deletions

View file

@ -4,7 +4,10 @@ import time
import torch
import pkg_resources
import yaml
import os
import logging
logger_instance = None
def load_yaml_config(file_name):
# Load the YAML file from the package
@ -134,3 +137,40 @@ class GuardHandler:
f"{self.task}_sentence": sentence,
}
return result_dict
def get_model_server_logger():
global logger_instance
if logger_instance is not None:
# If the logger is already initialized, return the existing instance
return logger_instance
# Define log file path outside current directory (e.g., ~/archgw_logs)
log_dir = os.path.expanduser("~/archgw_logs")
log_file = "modelserver.log"
log_file_path = os.path.join(log_dir, log_file)
# Ensure the log directory exists, create it if necessary, handle permissions errors
try:
if not os.path.exists(log_dir):
os.makedirs(log_dir, exist_ok=True) # Create directory if it doesn't exist
# Check if the script has write permission in the log directory
if not os.access(log_dir, os.W_OK):
raise PermissionError(f"No write permission for the directory: {log_dir}")
# Configure logging to file and console using basicConfig
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s",
handlers=[
logging.FileHandler(log_file_path, mode='w'), # Overwrite logs in file
]
)
except (PermissionError, OSError) as e:
# Dont' fallback to console logging if there are issues writing to the log file
raise RuntimeError(f"No write permission for the directory: {log_dir}")
# Initialize the logger instance after configuring handlers
logger_instance = logging.getLogger("model_server_logger")
return logger_instance