forked from LucienShui/huggingface-vscode-endpoint-server
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Each process now writes to its own log file. Documentation is in https://loguru.readthedocs.io/en/stable/overview.html For hints on how to format log message, see Delgan/loguru#586
- Loading branch information
1 parent
9f3beea
commit 10d4978
Showing
8 changed files
with
45 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
import logging | ||
import sys | ||
|
||
logging.basicConfig( | ||
format="%(asctime)s %(levelname)s %(message)s", | ||
level=logging.DEBUG, | ||
handlers=[ | ||
logging.FileHandler('app.log'), | ||
logging.StreamHandler() | ||
] | ||
) | ||
from app.util import ModelConfig, ApiConfig | ||
|
||
logger = logging.getLogger('app') | ||
|
||
def configure_logger(api_config: ApiConfig, model_config: ModelConfig): | ||
from loguru import logger | ||
|
||
class InterceptHandler(logging.Handler): | ||
def emit(self, record): | ||
# Get corresponding Loguru level if it exists. | ||
try: | ||
level = logger.level(record.levelname).name | ||
except ValueError: | ||
level = record.levelno | ||
|
||
# Find caller from where originated the logged message. | ||
frame, depth = sys._getframe(6), 6 | ||
while frame and frame.f_code.co_filename == logging.__file__: | ||
frame = frame.f_back | ||
depth += 1 | ||
|
||
logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage()) | ||
|
||
logger_format = "{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} | {message}" | ||
|
||
logging.basicConfig(handlers=[InterceptHandler()], level=0, force=True) | ||
|
||
logger.add(f"{api_config.api_type}_{model_config.model_name}" + "_{time}.log", format=logger_format, rotation="50MB", level="DEBUG") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters