-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add logging * simplify the logger * formatting * final touches * fix format * Model: Add log to metrics Signed-off-by: kingbri <[email protected]> --------- Authored-by: AlpinDale <[email protected]>
- Loading branch information
Showing
11 changed files
with
170 additions
and
74 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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
Logging utility. | ||
https://github.com/PygmalionAI/aphrodite-engine/blob/main/aphrodite/common/logger.py | ||
""" | ||
|
||
import logging | ||
import sys | ||
import colorlog | ||
|
||
_FORMAT = "%(log_color)s%(levelname)s: %(message)s" | ||
_DATE_FORMAT = "%m-%d %H:%M:%S" | ||
|
||
|
||
class ColoredFormatter(colorlog.ColoredFormatter): | ||
"""Adds logging prefix to newlines to align multi-line messages.""" | ||
|
||
def __init__(self, fmt, datefmt=None, log_colors=None, reset=True, style="%"): | ||
super().__init__( | ||
fmt, datefmt=datefmt, log_colors=log_colors, reset=reset, style=style | ||
) | ||
|
||
def format(self, record): | ||
msg = super().format(record) | ||
if record.message != "": | ||
parts = msg.split(record.message) | ||
msg = msg.replace("\n", "\r\n" + parts[0]) | ||
return msg | ||
|
||
|
||
_root_logger = logging.getLogger("aphrodite") | ||
_default_handler = None | ||
|
||
|
||
def _setup_logger(): | ||
_root_logger.setLevel(logging.DEBUG) | ||
global _default_handler | ||
if _default_handler is None: | ||
_default_handler = logging.StreamHandler(sys.stdout) | ||
_default_handler.flush = sys.stdout.flush # type: ignore | ||
_default_handler.setLevel(logging.INFO) | ||
_root_logger.addHandler(_default_handler) | ||
fmt = ColoredFormatter( | ||
_FORMAT, | ||
datefmt=_DATE_FORMAT, | ||
log_colors={ | ||
"DEBUG": "cyan", | ||
"INFO": "green", | ||
"WARNING": "yellow", | ||
"ERROR": "red", | ||
"CRITICAL": "red,bg_white", | ||
}, | ||
reset=True, | ||
) | ||
_default_handler.setFormatter(fmt) | ||
# Setting this will avoid the message | ||
# being propagated to the parent logger. | ||
_root_logger.propagate = False | ||
|
||
|
||
# The logger is initialized when the module is imported. | ||
# This is thread-safe as the module is only imported once, | ||
# guaranteed by the Python GIL. | ||
_setup_logger() | ||
|
||
|
||
def init_logger(name: str): | ||
logger = logging.getLogger(name) | ||
logger.setLevel(logging.DEBUG) | ||
logger.addHandler(_default_handler) | ||
logger.propagate = False | ||
return logger |
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ PyYAML | |
progress | ||
uvicorn | ||
jinja2 >= 3.0.0 | ||
colorlog |
Oops, something went wrong.