Skip to content

Commit

Permalink
add easier access to log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Sep 15, 2023
1 parent 38e123a commit f5a3fd5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
75 changes: 41 additions & 34 deletions core/cat/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,40 @@ 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
----------
msg :
Message to be logged.
level : str
Logging level."""

global logger
logger.remove()

Expand Down Expand Up @@ -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()
4 changes: 2 additions & 2 deletions core/cat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit f5a3fd5

Please sign in to comment.