forked from Rockachopa/Timmy-time-dashboard
fix: clean up logging colors, reduce noise, enable Tailscale access (#166)
* fix: reserve red for real errors, reduce log noise, allow Tailscale access - Add _ColorFormatter: red = ERROR/CRITICAL only, yellow = WARNING, green = INFO - Override uvicorn's default colors to use our scheme - Downgrade discord "not installed" from ERROR to WARNING (optional dep) - Downgrade DuckDuckGo unavailable from INFO to DEBUG - Stop discord token watcher retry loop when discord.py not installed - Add configurable trusted_hosts setting; dev mode allows all hosts - Exclude .claude/ from uvicorn reload watcher (worktree isolation) - Fix pre-commit hook: use tox -e unit, bump timeout to 60s Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style: auto-format with black Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: pre-commit hook auto-formats with black+isort before testing Formatting should never block a commit — just fix it automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Trip T <trip@local> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
1191ea2f9a
commit
c41e3e1e15
@@ -51,6 +51,24 @@ from dashboard.routes.work_orders import router as work_orders_router
|
||||
from infrastructure.router.api import router as cascade_router
|
||||
|
||||
|
||||
class _ColorFormatter(logging.Formatter):
|
||||
"""ANSI color formatter — red is reserved for ERROR/CRITICAL only."""
|
||||
|
||||
RESET = "\033[0m"
|
||||
COLORS = {
|
||||
logging.DEBUG: "\033[37m", # white/gray
|
||||
logging.INFO: "\033[32m", # green
|
||||
logging.WARNING: "\033[33m", # yellow
|
||||
logging.ERROR: "\033[31m", # red
|
||||
logging.CRITICAL: "\033[1;31m", # bold red
|
||||
}
|
||||
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
color = self.COLORS.get(record.levelno, self.RESET)
|
||||
formatted = super().format(record)
|
||||
return f"{color}{formatted}{self.RESET}"
|
||||
|
||||
|
||||
def _configure_logging() -> None:
|
||||
"""Configure logging with console and optional rotating file handler."""
|
||||
root_logger = logging.getLogger()
|
||||
@@ -59,13 +77,20 @@ def _configure_logging() -> None:
|
||||
console = logging.StreamHandler()
|
||||
console.setLevel(logging.INFO)
|
||||
console.setFormatter(
|
||||
logging.Formatter(
|
||||
_ColorFormatter(
|
||||
"%(asctime)s %(levelname)-8s %(name)s — %(message)s",
|
||||
datefmt="%H:%M:%S",
|
||||
)
|
||||
)
|
||||
root_logger.addHandler(console)
|
||||
|
||||
# Override uvicorn's default colored formatter so all console output
|
||||
# uses our color scheme (red = ERROR/CRITICAL only).
|
||||
for name in ("uvicorn", "uvicorn.error", "uvicorn.access"):
|
||||
uv_logger = logging.getLogger(name)
|
||||
uv_logger.handlers.clear()
|
||||
uv_logger.propagate = True
|
||||
|
||||
if settings.error_log_enabled:
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
@@ -175,6 +200,13 @@ async def _discord_token_watcher() -> None:
|
||||
"""Poll for DISCORD_TOKEN appearing in env or .env and auto-start Discord bot."""
|
||||
from integrations.chat_bridge.vendors.discord import discord_bot
|
||||
|
||||
# Don't poll if discord.py isn't even installed
|
||||
try:
|
||||
import discord as _discord_check # noqa: F401
|
||||
except ImportError:
|
||||
logger.debug("discord.py not installed — token watcher exiting")
|
||||
return
|
||||
|
||||
while True:
|
||||
await asyncio.sleep(30)
|
||||
|
||||
@@ -325,9 +357,11 @@ app.add_middleware(SecurityHeadersMiddleware, production=not settings.debug)
|
||||
app.add_middleware(CSRFMiddleware)
|
||||
|
||||
# 4. Standard FastAPI middleware
|
||||
# In development, allow all hosts (Tailscale IPs, MagicDNS, etc.)
|
||||
_trusted = settings.trusted_hosts if settings.timmy_env == "production" else ["*"]
|
||||
app.add_middleware(
|
||||
TrustedHostMiddleware,
|
||||
allowed_hosts=["localhost", "127.0.0.1", "*.local", "testserver"],
|
||||
allowed_hosts=_trusted,
|
||||
)
|
||||
|
||||
app.add_middleware(
|
||||
|
||||
Reference in New Issue
Block a user