Skip to content

Commit 54e9d06

Browse files
authored
Merge pull request #26 from tisnik/proper-logging
Proper logging in the service
2 parents 1f626e5 + 15052f2 commit 54e9d06

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import yaml
22

3+
import logging
34
from typing import Any, Optional
45
from models.config import Configuration, LLamaStackConfiguration
56

7+
logger = logging.getLogger(__name__)
8+
69

710
class AppConfig:
811
_instance = None
@@ -21,7 +24,7 @@ def load_configuration(self, filename: str) -> None:
2124
"""Load configuration from YAML file."""
2225
with open(filename, encoding="utf-8") as fin:
2326
config_dict = yaml.safe_load(fin)
24-
print(config_dict)
27+
logger.info("Loaded configuration: %s", config_dict)
2528
self._configuration = Configuration(**config_dict)
2629

2730
@property

src/lightspeed-stack.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
"""Lightspeed stack."""
22

3+
import logging
34
from runners.uvicorn import start_uvicorn
45
from models.config import Configuration
56
from configuration import configuration
67

8+
from rich.logging import RichHandler
9+
10+
FORMAT = "%(message)s"
11+
logging.basicConfig(
12+
level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
13+
) # set level=20 or logging.INFO to turn off debug
14+
logger = logging.getLogger("rich")
15+
16+
logging.basicConfig(level=logging.INFO)
17+
logger = logging.getLogger(__name__)
718

819
if __name__ == "__main__":
9-
print("Lightspeed stack")
20+
logger.info("Lightspeed stack startup")
1021
configuration.load_configuration("lightspeed-stack.yaml")
11-
print(configuration)
12-
print(configuration.llama_stack_configuration)
22+
logger.info("Configuration: %s", configuration.configuration)
23+
logger.info(
24+
"Llama stack configuration: %s", configuration.llama_stack_configuration
25+
)
1326
start_uvicorn()
27+
logger.info("Lightspeed stack finished")

src/runners/uvicorn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ def start_uvicorn() -> None:
1414
host = "localhost"
1515
port = 8080
1616
workers = 1
17+
log_level = logging.INFO
1718

1819
uvicorn.run(
1920
"app.main:app",
2021
host=host,
2122
port=port,
2223
workers=workers,
24+
log_level=log_level,
2325
)

0 commit comments

Comments
 (0)