Initial commit: bot Discord Vicy V1.8
This commit is contained in:
commit
56958c5832
70 changed files with 8469 additions and 0 deletions
34
utils/logger.py
Normal file
34
utils/logger.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import logging
|
||||
from datetime import datetime
|
||||
import pytz # Nécessite le package pytz
|
||||
|
||||
# Définir le fuseau horaire France
|
||||
paris_tz = pytz.timezone("Europe/Paris")
|
||||
|
||||
class FranceFormatter(logging.Formatter):
|
||||
def formatTime(self, record, datefmt=None):
|
||||
dt = datetime.fromtimestamp(record.created, tz=paris_tz)
|
||||
if datefmt:
|
||||
return dt.strftime(datefmt)
|
||||
return dt.isoformat()
|
||||
|
||||
# Création du logger
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
# Handler vers fichier
|
||||
file_handler = logging.FileHandler("log.txt", encoding="utf-8")
|
||||
formatter = FranceFormatter("%(asctime)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
|
||||
file_handler.setFormatter(formatter)
|
||||
|
||||
logger.addHandler(file_handler)
|
||||
|
||||
# Fonctions de log
|
||||
def log_info(message):
|
||||
logger.info(message)
|
||||
|
||||
def log_warning(message):
|
||||
logger.warning(message)
|
||||
|
||||
def log_error(message):
|
||||
logger.error(message)
|
||||
Loading…
Add table
Add a link
Reference in a new issue