-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,21 @@ | ||
import logging | ||
import sys | ||
from coinbase_advanced_trader.config import config_manager | ||
|
||
import logging | ||
|
||
def setup_logger(): | ||
""" | ||
Set up and configure the logger for the Coinbase Advanced Trader application. | ||
logger = logging.getLogger("coinbase_advanced_trader") | ||
logger.setLevel(logging.INFO) | ||
|
||
Returns: | ||
logging.Logger: Configured logger instance. | ||
""" | ||
log_file_path = config_manager.get('LOG_FILE_PATH') | ||
log_level = config_manager.get('LOG_LEVEL') | ||
# Create a stream handler that writes to sys.stdout | ||
handler = logging.StreamHandler(sys.stdout) | ||
handler.setLevel(logging.INFO) | ||
|
||
logger = logging.getLogger('coinbase_advanced_trader') | ||
logger.setLevel(getattr(logging, log_level)) | ||
# Create a formatter and add it to the handler | ||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
handler.setFormatter(formatter) | ||
|
||
# Console handler | ||
console_handler = logging.StreamHandler(sys.stdout) | ||
console_handler.setLevel(logging.INFO) | ||
console_formatter = logging.Formatter( | ||
'%(asctime)s - %(levelname)s - %(message)s' | ||
) | ||
console_handler.setFormatter(console_formatter) | ||
|
||
# File handler | ||
file_handler = logging.FileHandler(log_file_path) | ||
file_handler.setLevel(logging.DEBUG) | ||
file_formatter = logging.Formatter( | ||
'%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d - %(message)s' | ||
) | ||
file_handler.setFormatter(file_formatter) | ||
|
||
# Add handlers to logger | ||
logger.addHandler(console_handler) | ||
logger.addHandler(file_handler) | ||
# Add the handler to the logger | ||
logger.addHandler(handler) | ||
|
||
return logger | ||
|
||
|
||
logger = setup_logger() |