Skip to content

Commit

Permalink
Merge pull request #84 from rhettre/bugfix/logger-for-cloud
Browse files Browse the repository at this point in the history
Update logger.py
  • Loading branch information
rhettre authored Jul 27, 2024
2 parents 84971ea + 97bc9aa commit 18fa0a6
Showing 1 changed file with 11 additions and 32 deletions.
43 changes: 11 additions & 32 deletions coinbase_advanced_trader/logger.py
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()

0 comments on commit 18fa0a6

Please sign in to comment.