mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-24 08:03:53 +08:00
🦄 refactor(log): colorful log
This commit is contained in:
+5
-5
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
from config.logger import setup_logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
TAG = __name__
|
||||
|
||||
|
||||
class AuthenticationError(Exception):
|
||||
@@ -37,15 +37,15 @@ class AuthMiddleware:
|
||||
# 验证Authorization header
|
||||
auth_header = headers.get("authorization", "")
|
||||
if not auth_header.startswith("Bearer "):
|
||||
logger.error("Missing or invalid Authorization header")
|
||||
logger.bind(tag=TAG).error("Missing or invalid Authorization header")
|
||||
raise AuthenticationError("Missing or invalid Authorization header")
|
||||
|
||||
token = auth_header.split(" ")[1]
|
||||
if token not in self.tokens:
|
||||
logger.error(f"Invalid token: {token}")
|
||||
logger.bind(tag=TAG).error(f"Invalid token: {token}")
|
||||
raise AuthenticationError("Invalid token")
|
||||
|
||||
logger.info(f"Authentication successful - Device: {device_id}, Token: {self.tokens[token]}")
|
||||
logger.bind(tag=TAG).info(f"Authentication successful - Device: {device_id}, Token: {self.tokens[token]}")
|
||||
return True
|
||||
|
||||
def get_token_name(self, token):
|
||||
|
||||
Reference in New Issue
Block a user