Refactor code for improved readability and consistency
- Cleaned up whitespace and formatting in various files including http.py, language.py, logger.py, safe_exec.py, and SQL migration scripts. - Consolidated import statements and removed unnecessary blank lines. - Updated logging configuration for better clarity. - Enhanced the safe execution code with improved error handling and logging. - Removed commented-out code and unnecessary variables in backfill_zero_trades.py and other scripts. - Added a pyproject.toml for Ruff and Vulture configuration. - Introduced requirements-dev.txt for development dependencies. - Removed commented-out stock entries in init.sql for cleaner migration scripts.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Logging utilities (local-only friendly).
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from logging.handlers import RotatingFileHandler
|
||||
@@ -8,35 +9,32 @@ from logging.handlers import RotatingFileHandler
|
||||
|
||||
def setup_logger():
|
||||
"""Configure global logs"""
|
||||
log_level = os.getenv('LOG_LEVEL', 'INFO')
|
||||
log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
|
||||
logging.basicConfig(
|
||||
level=getattr(logging, log_level.upper()),
|
||||
format=log_format
|
||||
)
|
||||
|
||||
log_level = os.getenv("LOG_LEVEL", "INFO")
|
||||
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
|
||||
logging.basicConfig(level=getattr(logging, log_level.upper()), format=log_format)
|
||||
|
||||
# Filter werkzeug's INFO level logs (reduce noise)
|
||||
# Only keep WARNING and above levels
|
||||
werkzeug_logger = logging.getLogger('werkzeug')
|
||||
werkzeug_logger = logging.getLogger("werkzeug")
|
||||
werkzeug_logger.setLevel(logging.WARNING)
|
||||
|
||||
|
||||
# Filter INFO level logs for kline routes (reduce noise)
|
||||
# Only keep WARNING and above levels
|
||||
kline_logger = logging.getLogger('app.routes.kline')
|
||||
kline_logger = logging.getLogger("app.routes.kline")
|
||||
kline_logger.setLevel(logging.WARNING)
|
||||
|
||||
|
||||
# Create log directory
|
||||
log_dir = 'logs'
|
||||
log_dir = "logs"
|
||||
if not os.path.exists(log_dir):
|
||||
os.makedirs(log_dir)
|
||||
|
||||
|
||||
# Add file handler
|
||||
file_handler = RotatingFileHandler(
|
||||
os.path.join(log_dir, 'app.log'),
|
||||
maxBytes=10*1024*1024, # 10MB
|
||||
os.path.join(log_dir, "app.log"),
|
||||
maxBytes=10 * 1024 * 1024, # 10MB
|
||||
backupCount=5,
|
||||
encoding='utf-8'
|
||||
encoding="utf-8",
|
||||
)
|
||||
file_handler.setFormatter(logging.Formatter(log_format))
|
||||
logging.getLogger().addHandler(file_handler)
|
||||
@@ -45,12 +43,11 @@ def setup_logger():
|
||||
def get_logger(name: str) -> logging.Logger:
|
||||
"""
|
||||
Get the logger with the specified name
|
||||
|
||||
|
||||
Args:
|
||||
name: logger name
|
||||
|
||||
|
||||
Returns:
|
||||
Logger instance
|
||||
"""
|
||||
return logging.getLogger(name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user