54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
import logging
|
|
|
|
import coloredlogs
|
|
|
|
from llm_server import globals
|
|
|
|
|
|
class LoggingInfo:
|
|
def __init__(self):
|
|
self._level = logging.INFO
|
|
self._format = globals.LOGGING_FORMAT
|
|
|
|
@property
|
|
def level(self):
|
|
return self._level
|
|
|
|
@level.setter
|
|
def level(self, value):
|
|
self._level = value
|
|
|
|
@property
|
|
def format(self):
|
|
return self._format
|
|
|
|
@format.setter
|
|
def format(self, value):
|
|
self._format = value
|
|
|
|
|
|
logging_info = LoggingInfo()
|
|
|
|
|
|
def init_logging():
|
|
"""
|
|
Set up the parent logger. Ensures this logger and all children to log to a file.
|
|
This is only called by `server.py` since there is wierdness with Gunicorn. The deamon doesn't need this.
|
|
:return:
|
|
"""
|
|
logger = logging.getLogger('llm_server')
|
|
logger.setLevel(logging_info.level)
|
|
|
|
|
|
def create_logger(name):
|
|
logger = logging.getLogger('llm_server').getChild(name)
|
|
logger.setLevel(logging_info.level)
|
|
if not logger.handlers:
|
|
handler = logging.StreamHandler()
|
|
handler.setLevel(logging_info.level)
|
|
formatter = logging.Formatter(logging_info.format)
|
|
handler.setFormatter(formatter)
|
|
logger.addHandler(handler)
|
|
coloredlogs.install(logger=logger, level=logging_info.level)
|
|
return logger
|