[Refactor] Improve logging package wide (#1315)
This commit is contained in:
@@ -12,10 +12,12 @@ intents.message_content = True
|
||||
client = discord.Client(intents=intents)
|
||||
discord_bot_name = os.environ["DISCORD_BOT_NAME"]
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NextJSBot:
|
||||
def __init__(self) -> None:
|
||||
logging.info("NextJS Bot powered with embedchain.")
|
||||
logger.info("NextJS Bot powered with embedchain.")
|
||||
|
||||
def add(self, _):
|
||||
raise ValueError("Add is not implemented yet")
|
||||
@@ -31,11 +33,11 @@ class NextJSBot:
|
||||
try:
|
||||
response = response.json()
|
||||
except Exception:
|
||||
logging.error(f"Failed to parse response: {response}")
|
||||
logger.error(f"Failed to parse response: {response}")
|
||||
response = {}
|
||||
return response
|
||||
except Exception:
|
||||
logging.exception(f"Failed to query {message}.")
|
||||
logger.exception(f"Failed to query {message}.")
|
||||
response = "An error occurred. Please try again!"
|
||||
return response
|
||||
|
||||
@@ -49,7 +51,7 @@ NEXTJS_BOT = NextJSBot()
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
logging.info(f"User {client.user.name} logged in with id: {client.user.id}!")
|
||||
logger.info(f"User {client.user.name} logged in with id: {client.user.id}!")
|
||||
|
||||
|
||||
def _get_question(message):
|
||||
|
||||
@@ -9,6 +9,8 @@ from slack_bolt.adapter.socket_mode import SocketModeHandler
|
||||
|
||||
load_dotenv(".env")
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def remove_mentions(message):
|
||||
mention_pattern = re.compile(r"<@[^>]+>")
|
||||
@@ -19,7 +21,7 @@ def remove_mentions(message):
|
||||
|
||||
class SlackBotApp:
|
||||
def __init__(self) -> None:
|
||||
logging.info("Slack Bot using Embedchain!")
|
||||
logger.info("Slack Bot using Embedchain!")
|
||||
|
||||
def add(self, _):
|
||||
raise ValueError("Add is not implemented yet")
|
||||
@@ -35,11 +37,11 @@ class SlackBotApp:
|
||||
try:
|
||||
response = response.json()
|
||||
except Exception:
|
||||
logging.error(f"Failed to parse response: {response}")
|
||||
logger.error(f"Failed to parse response: {response}")
|
||||
response = {}
|
||||
return response
|
||||
except Exception:
|
||||
logging.exception(f"Failed to query {query}.")
|
||||
logger.exception(f"Failed to query {query}.")
|
||||
response = "An error occurred. Please try again!"
|
||||
return response
|
||||
|
||||
|
||||
Reference in New Issue
Block a user