feat: Reimplement the deployment process through Docker
Some checks failed
CI / Run tests (pull_request) Has been cancelled
Some checks failed
CI / Run tests (pull_request) Has been cancelled
This commit is contained in:
@@ -7,19 +7,11 @@ class Config:
|
||||
|
||||
TOKEN = str(os.getenv("TOKEN", ""))
|
||||
CONFIG_PATH = str(os.getenv("CONFIG_PATH"))
|
||||
COGS = os.getenv("COGS", "")
|
||||
|
||||
GUILDS_IDS:list[int] = []
|
||||
|
||||
GUILD_CONFIGS:dict[int,dict] = {}
|
||||
|
||||
@classmethod
|
||||
def get_cogs(cls):
|
||||
raw_value = cls.COGS.strip()
|
||||
if not raw_value:
|
||||
return None
|
||||
return [item.strip().lower() for item in raw_value.split(",") if item.strip()]
|
||||
|
||||
@classmethod
|
||||
def load_guilds_configs(cls):
|
||||
with os.scandir(cls.CONFIG_PATH) as d:
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
import sys
|
||||
|
||||
# Determine log level from environment variable `LOG_LEVEL` (e.g. DEBUG, INFO)
|
||||
raw_level = os.getenv("LOG_LEVEL", "INFO").upper()
|
||||
@@ -15,7 +17,26 @@ else:
|
||||
logging.basicConfig(level=level, format='[%(levelname)s] %(asctime)s: %(name)s: %(message)s')
|
||||
LOGGER = logging.getLogger('botmafieux')
|
||||
LOGGER.setLevel(level)
|
||||
# File handler (append)
|
||||
handler = logging.FileHandler(filename='botmafieux.log', encoding='utf-8', mode='a')
|
||||
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
|
||||
LOGGER.addHandler(handler)
|
||||
|
||||
# Decide log file path: prefer LOG_FILE, then CONFIG_PATH/botmafieux.log, then /tmp
|
||||
preferred = os.getenv('LOG_FILE')
|
||||
if not preferred:
|
||||
cfg_path = "/logs"
|
||||
if cfg_path:
|
||||
preferred = os.path.join(cfg_path, 'botmafieux.log')
|
||||
else:
|
||||
preferred = os.path.join(tempfile.gettempdir(), 'botmafieux.log')
|
||||
|
||||
formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s')
|
||||
|
||||
try:
|
||||
handler = logging.FileHandler(filename=preferred, encoding='utf-8', mode='a')
|
||||
handler.setFormatter(formatter)
|
||||
LOGGER.addHandler(handler)
|
||||
except (PermissionError, OSError) as e:
|
||||
# Fall back to console logging if file cannot be opened
|
||||
stream_handler = logging.StreamHandler(sys.stdout)
|
||||
stream_handler.setFormatter(formatter)
|
||||
LOGGER.addHandler(stream_handler)
|
||||
# Print a warning directly to stderr in case logging isn't yet configured elsewhere
|
||||
print(f"[WARN] Could not open log file '{preferred}' for writing: {e}. Falling back to stdout.", file=sys.stderr)
|
||||
Reference in New Issue
Block a user