Commit
•
0a22847
1
Parent(s):
82e111a
adds color (#425)
Browse files* adds color
* chore: lint
* fix for colorama
---------
Co-authored-by: Wing Lian <wing.lian@gmail.com>
- requirements.txt +1 -0
- src/axolotl/logging_config.py +39 -2
requirements.txt
CHANGED
@@ -12,6 +12,7 @@ einops
|
|
12 |
xformers
|
13 |
optimum
|
14 |
hf_transfer
|
|
|
15 |
numba
|
16 |
numpy==1.24.4
|
17 |
# qlora things
|
|
|
12 |
xformers
|
13 |
optimum
|
14 |
hf_transfer
|
15 |
+
colorama
|
16 |
numba
|
17 |
numpy==1.24.4
|
18 |
# qlora things
|
src/axolotl/logging_config.py
CHANGED
@@ -1,16 +1,42 @@
|
|
1 |
-
"""
|
|
|
|
|
2 |
|
3 |
import os
|
4 |
import sys
|
|
|
5 |
from logging.config import dictConfig
|
6 |
from typing import Any, Dict
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
DEFAULT_LOGGING_CONFIG: Dict[str, Any] = {
|
9 |
"version": 1,
|
10 |
"formatters": {
|
11 |
"simple": {
|
12 |
"format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s:%(lineno)d] [PID:%(process)d] %(message)s",
|
13 |
},
|
|
|
|
|
|
|
|
|
14 |
},
|
15 |
"filters": {},
|
16 |
"handlers": {
|
@@ -20,14 +46,25 @@ DEFAULT_LOGGING_CONFIG: Dict[str, Any] = {
|
|
20 |
"filters": [],
|
21 |
"stream": sys.stdout,
|
22 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
},
|
24 |
"root": {"handlers": ["console"], "level": os.getenv("LOG_LEVEL", "INFO")},
|
25 |
"loggers": {
|
26 |
-
"axolotl": {
|
|
|
|
|
|
|
|
|
27 |
},
|
28 |
}
|
29 |
|
30 |
|
31 |
def configure_logging():
|
32 |
"""Configure with default logging"""
|
|
|
33 |
dictConfig(DEFAULT_LOGGING_CONFIG)
|
|
|
1 |
+
"""
|
2 |
+
Common logging module for axolotl
|
3 |
+
"""
|
4 |
|
5 |
import os
|
6 |
import sys
|
7 |
+
from logging import Formatter
|
8 |
from logging.config import dictConfig
|
9 |
from typing import Any, Dict
|
10 |
|
11 |
+
from colorama import Fore, Style, init
|
12 |
+
|
13 |
+
|
14 |
+
class ColorfulFormatter(Formatter):
|
15 |
+
"""
|
16 |
+
Formatter to add coloring to log messages by log type
|
17 |
+
"""
|
18 |
+
|
19 |
+
COLORS = {
|
20 |
+
"WARNING": Fore.YELLOW,
|
21 |
+
"ERROR": Fore.RED,
|
22 |
+
"CRITICAL": Fore.RED + Style.BRIGHT,
|
23 |
+
}
|
24 |
+
|
25 |
+
def format(self, record):
|
26 |
+
log_message = super().format(record)
|
27 |
+
return self.COLORS.get(record.levelname, "") + log_message + Fore.RESET
|
28 |
+
|
29 |
+
|
30 |
DEFAULT_LOGGING_CONFIG: Dict[str, Any] = {
|
31 |
"version": 1,
|
32 |
"formatters": {
|
33 |
"simple": {
|
34 |
"format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s:%(lineno)d] [PID:%(process)d] %(message)s",
|
35 |
},
|
36 |
+
"colorful": {
|
37 |
+
"()": ColorfulFormatter,
|
38 |
+
"format": "[%(asctime)s] [%(levelname)s] [%(name)s.%(funcName)s:%(lineno)d] [PID:%(process)d] %(message)s",
|
39 |
+
},
|
40 |
},
|
41 |
"filters": {},
|
42 |
"handlers": {
|
|
|
46 |
"filters": [],
|
47 |
"stream": sys.stdout,
|
48 |
},
|
49 |
+
"color_console": {
|
50 |
+
"class": "logging.StreamHandler",
|
51 |
+
"formatter": "colorful",
|
52 |
+
"filters": [],
|
53 |
+
"stream": sys.stdout,
|
54 |
+
},
|
55 |
},
|
56 |
"root": {"handlers": ["console"], "level": os.getenv("LOG_LEVEL", "INFO")},
|
57 |
"loggers": {
|
58 |
+
"axolotl": {
|
59 |
+
"handlers": ["color_console"],
|
60 |
+
"level": "DEBUG",
|
61 |
+
"propagate": False,
|
62 |
+
},
|
63 |
},
|
64 |
}
|
65 |
|
66 |
|
67 |
def configure_logging():
|
68 |
"""Configure with default logging"""
|
69 |
+
init() # Initialize colorama
|
70 |
dictConfig(DEFAULT_LOGGING_CONFIG)
|