Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
55 lines (48 loc) · 2.07 KB
/
Copy pathconfig.py
File metadata and controls
55 lines (48 loc) · 2.07 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
import os
import logging
from dataclasses import dataclass
from typing import List, Optional
@dataclass
class Config:
"""Application configuration"""
arcade_api_key: str
openai_api_key: str
slack_bot_token: str
slack_app_token: str
log_level: str = "INFO"
@classmethod
def from_env(cls) -> Optional['Config']:
"""Load configuration from environment variables"""
return cls(
arcade_api_key=os.getenv("ARCADE_API_KEY", ""),
openai_api_key=os.getenv("OPENAI_API_KEY", ""),
slack_bot_token=os.getenv("SLACK_BOT_TOKEN", ""),
slack_app_token=os.getenv("SLACK_APP_TOKEN", ""),
log_level=os.getenv("LOG_LEVEL", "INFO")
)
def validate(self) -> List[str]:
"""Validate configuration and return list of missing variables"""
missing = []
if not self.arcade_api_key:
missing.append("ARCADE_API_KEY")
if not self.openai_api_key:
missing.append("OPENAI_API_KEY")
if not self.slack_bot_token:
missing.append("SLACK_BOT_TOKEN")
if not self.slack_app_token:
missing.append("SLACK_APP_TOKEN")
return missing
def setup_logging(level: str = "INFO"):
"""Configure application logging"""
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logging.basicConfig(
level=getattr(logging, level.upper()),
format=log_format
)
# Logger levels for noise reduction
logging.getLogger("slack_bolt").setLevel(logging.WARNING) # Silences slackbolt messages with level warning
logging.getLogger("slack_sdk").setLevel(logging.WARNING) # Silences sdk messages with level warning
logging.getLogger("slack_bolt.AsyncApp").setLevel(logging.WARNING) # Silences asyncapp messages with level warning
logging.getLogger("httpx").setLevel(logging.WARNING) # Silences httpx messages with level warning
logging.getLogger("websocket").setLevel(logging.WARNING) # Silences websocket messages with level warning
return logging.getLogger("flyme")