-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_config.py
More file actions
76 lines (62 loc) · 2.13 KB
/
logger_config.py
File metadata and controls
76 lines (62 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Logging configuration for ClickUp Task Creator.
This module sets up Rich-enhanced logging with:
- Colorful console output
- Optional file logging
- Debug/Info/Error levels
- Rich tracebacks for better error debugging
"""
import logging
import sys
from pathlib import Path
from typing import Optional
from rich.console import Console
from rich.logging import RichHandler
from rich.traceback import install
def setup_logging(
level: int = logging.INFO,
log_file: Optional[str] = None,
use_rich: bool = True
) -> logging.Logger:
"""Set up logging with Rich console handler and optional file handler.
Args:
level: Logging level (logging.DEBUG, logging.INFO, etc.)
log_file: Optional path to log file for persistent logging
use_rich: Whether to use Rich formatting (default: True)
Returns:
Configured logger instance
"""
# Install Rich tracebacks for better error messages
if use_rich:
install(show_locals=True)
# Create logger
logger = logging.getLogger("clickup_task_creator")
logger.setLevel(level)
# Remove existing handlers to avoid duplicates
logger.handlers.clear()
# Console handler with Rich formatting
if use_rich:
console_handler = RichHandler(
rich_tracebacks=True,
markup=True,
show_time=True,
show_level=True,
show_path=True
)
else:
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setFormatter(
logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
)
console_handler.setLevel(level)
logger.addHandler(console_handler)
# File handler if log_file is specified
if log_file:
log_path = Path(log_file)
log_path.parent.mkdir(parents=True, exist_ok=True)
file_handler = logging.FileHandler(log_path)
file_handler.setLevel(level)
file_handler.setFormatter(
logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
)
logger.addHandler(file_handler)
return logger