diff --git a/core/cat/log.py b/core/cat/log.py index 506d80f9..e199b2b8 100644 --- a/core/cat/log.py +++ b/core/cat/log.py @@ -140,8 +140,32 @@ def get_caller_info(self, skip=3): return package, module, klass, caller, line + def __call__(self, msg, level="DEBUG"): + """Alias of self.log()""" + self.log(msg, level) + + def debug(self, msg): + """Logs a DEBUG message""" + self.log(msg, level="DEBUG") + + def info(self, msg): + """Logs an INFO message""" + self.log(msg, level="INFO") + + def warning(self, msg): + """Logs a WARNING message""" + self.log(msg, level="WARNING") + + def error(self, msg): + """Logs an ERROR message""" + self.log(msg, level="ERROR") + + def critical(self, msg): + """Logs a CRITICAL message""" + self.log(msg, level="CRITICAL") + def log(self, msg, level="DEBUG"): - """Add to log based on settings. + """Log a message Parameters ---------- @@ -149,6 +173,7 @@ def log(self, msg, level="DEBUG"): Message to be logged. level : str Logging level.""" + global logger logger.remove() @@ -203,40 +228,22 @@ def log(self, msg, level="DEBUG"): # After our custom log we need to set again the logger as default for the other dependencies self.default_log() + def welcome(self): + """Welcome message in the terminal.""" + secure = os.getenv('CORE_USE_SECURE_PROTOCOLS', '') + if secure != '': + secure = 's' -logEngine = CatLogEngine() - - -def log(msg, level="DEBUG"): - """Create function wrapper to class. - - Parameters - ---------- - msg : str - Message to be logged. - level : str - Logging level. - - Returns - ------- - """ - global logEngine - return logEngine.log(msg, level) - - -def welcome(): - """Welcome message in the terminal.""" - secure = os.getenv('CORE_USE_SECURE_PROTOCOLS', '') - if secure != '': - secure = 's' + cat_address = f'http{secure}://{os.environ["CORE_HOST"]}:{os.environ["CORE_PORT"]}' - cat_address = f'http{secure}://{os.environ["CORE_HOST"]}:{os.environ["CORE_PORT"]}' + with open("cat/welcome.txt", 'r') as f: + print(f.read()) - with open("cat/welcome.txt", 'r') as f: - print(f.read()) + print('\n=============== ^._.^ ===============\n') + print(f'Cat REST API:\t{cat_address}/docs') + print(f'Cat PUBLIC:\t{cat_address}/public') + print(f'Cat ADMIN:\t{cat_address}/admin\n') + print('======================================') - print('\n=============== ^._.^ ===============\n') - print(f'Cat REST API:\t{cat_address}/docs') - print(f'Cat PUBLIC:\t{cat_address}/public') - print(f'Cat ADMIN:\t{cat_address}/admin\n') - print('======================================') +# logger instance +log = CatLogEngine() \ No newline at end of file diff --git a/core/cat/main.py b/core/cat/main.py index ceae9508..b93801fa 100644 --- a/core/cat/main.py +++ b/core/cat/main.py @@ -9,7 +9,7 @@ from fastapi.exceptions import RequestValidationError from fastapi.middleware.cors import CORSMiddleware -from cat.log import log, welcome +from cat.log import log from cat.routes import base, settings, llm, embedder, memory, plugins, upload, websocket from cat.routes.static import public, admin, static from cat.api_auth import check_api_key @@ -29,7 +29,7 @@ async def lifespan(app: FastAPI): app.state.ccat = CheshireCat() # startup message with admin, public and swagger addresses - welcome() + log.welcome() yield