Skip to content

Commit

Permalink
Merge branch 'sambarza-plugin-module-name-in-log' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Sep 15, 2023
2 parents b70f7b7 + f5a3fd5 commit 9369a31
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 38 deletions.
79 changes: 43 additions & 36 deletions core/cat/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ def get_caller_info(self, skip=3):
if module_info:
mod = module_info.__name__.split(".")
package = mod[0]
module = mod[1]
module = ".".join(mod[1:])

# class name.
klass = None
klass = ""
if "self" in parentframe.f_locals:
klass = parentframe.f_locals["self"].__class__.__name__

Expand All @@ -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 9369a31

Please sign in to comment.