Skip to content

Commit b9317a2

Browse files
authored
feat: add logger to support modular log output (#29)
<!-- Thanks for creating this pull request 🤗 Please make sure that the pull request is limited to one type (docs, feature, etc.) and keep it as small as possible. You can open multiple prs instead of opening a huge one. --> <!-- If this pull request closes an issue, please mention the issue number below --> <!-- Issue # here --> ## 📑 Description <!-- Add a brief description of the pr --> add logger to support modular log output <!-- You can also choose to add a list of changes and if they have been completed or not by using the markdown to-do list syntax - [ ] Not Completed - [x] Completed --> ## ✅ Checks <!-- Make sure your pr passes the CI checks and do check the following fields as needed - --> - [x] My pull request adheres to the code style of this project - [x] My code requires changes to the documentation - [x] I have updated the documentation as required - [x] All the tests have passed - [ ] Branch name follows `type/descript` (e.g. `feature/add-llm-agents`) - [x] Ready for code review ## ℹ Additional Information <!-- Any additional information like breaking changes, dependencies added, screenshots, comparisons between new and old behavior, etc. -->
1 parent 59275e8 commit b9317a2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

trading_bench/utils/logger.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import logging
2+
from typing import Optional
3+
4+
def setup_logger(name: str, level: int = logging.INFO) -> logging.Logger:
5+
"""
6+
Set up a logger with the specified name and logging level.
7+
8+
Args:
9+
name (str): Name of the logger.
10+
level (int, optional): Logging level (default is logging.INFO).
11+
12+
Returns:
13+
logging.Logger: Configured logger instance.
14+
"""
15+
logger = logging.getLogger(name)
16+
logger.setLevel(level)
17+
18+
# Avoid adding multiple handlers if logger already has handlers
19+
if not logger.handlers:
20+
# Create console handler and set level
21+
ch = logging.StreamHandler()
22+
ch.setLevel(level)
23+
24+
# Create formatter and add it to the handler
25+
formatter = logging.Formatter(
26+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
27+
)
28+
ch.setFormatter(formatter)
29+
30+
# Add the handler to the logger
31+
logger.addHandler(ch)
32+
33+
return logger

0 commit comments

Comments
 (0)