log debug → info

This commit is contained in:
Milka64 2021-01-06 20:33:16 +01:00
parent ef24e2a2bf
commit e790569a27
2 changed files with 26 additions and 10 deletions

View file

@ -3,12 +3,12 @@ FROM alpine
WORKDIR /app WORKDIR /app
VOLUME /data VOLUME /data
RUN apk add --update musl-dev python3-dev gcc python3 py3-pip git py3-lxml libxml2 libxml2-dev py3-pynacl\ RUN apk add --update musl-dev python3-dev gcc python3 py3-pip git py3-lxml libxml2 libxml2-dev py3-pynacl ffmpeg\
&& pip3 install --upgrade pip \ && pip3 install --upgrade pip \
&& pip3 install bs4 requests giphy_client discord.py python-gitlab\ && pip3 install bs4 requests giphy_client discord.py python-gitlab\
&& git clone https://git.0w.tf/Milka64/kabot.git && git clone https://git.0w.tf/Milka64/kabot.git
WORKDIR /app/kabot WORKDIR /app/kabot
RUN python3 bootstrap-buildout.py \ RUN pip3 install kabot/
&& bin/buildout RUN mkdir -p /var/log/kabot/
RUN chmod 777 /var/log/kabot
CMD bin/kabot CMD kabot -c /data/config.ini

View file

@ -30,31 +30,40 @@ here = os.path.dirname(os.path.abspath(__file__))
## création de l'objet logger ## création de l'objet logger
logger = logging.getLogger() logger = logging.getLogger()
## definition du log level ## definition du log level
logger.setLevel(logging.DEBUG) logger.setLevel(logging.INFO)
## format du log ## format du log
formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s') formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
## definition du fichier de log (chemin, level, etc ...) ## definition du fichier de log (chemin, level, etc ...)
file_handler = RotatingFileHandler('/var/log/kabot/kabot.log', 'a', 1000000, 1) file_handler = RotatingFileHandler('/var/log/kabot/kabot.log', 'a', 1000000, 1)
file_handler.setLevel(logging.DEBUG) file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter) file_handler.setFormatter(formatter)
logger.addHandler(file_handler) logger.addHandler(file_handler)
## definition de l'affichage des logs dans la console ## definition de l'affichage des logs dans la console
stream_handler = logging.StreamHandler() stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG) stream_handler.setLevel(logging.INFO)
logger.addHandler(stream_handler) logger.addHandler(stream_handler)
class Mybot(commands.Cog): class Mybot(commands.Cog):
#Fonctions necesaires pour Kabot. #Fonctions necesaires pour Kabot.
def __init__(self, bot, gl_url=None, gl_token=None, gif_token=None, audio_path=None): def __init__(
self,
bot,
gl_url=None,
gl_token=None,
gif_token=None,
audio_path=None,
nickname=None,
):
self.gl_url = gl_url self.gl_url = gl_url
self.audio_path = audio_path self.audio_path = audio_path
self.gl_token = gl_token self.gl_token = gl_token
self.gif_token = gif_token self.gif_token = gif_token
self.bot = bot self.bot = bot
self.sounds = [] self.sounds = []
self.nickname = nickname
self.sounds_history = [] self.sounds_history = []
self.play_next.start() self.play_next.start()
@ -554,6 +563,10 @@ def main():
logger.critical('config file not found') logger.critical('config file not found')
exit(1) exit(1)
config.read(args.config) config.read(args.config)
if "nickname" in config['DEFAULT']:
nickname = config['DEFAULT']['nickname']
else:
nickname = None
audio_path = config['DEFAULT']['audio_path'] audio_path = config['DEFAULT']['audio_path']
token = config['discord']['token'] token = config['discord']['token']
gl_url = config['gitlab']['url'] gl_url = config['gitlab']['url']
@ -618,6 +631,8 @@ def main():
for channel in bot.get_all_channels(): for channel in bot.get_all_channels():
if channel.name == "général": if channel.name == "général":
current_chan = channel current_chan = channel
if nickname:
await bot.user.edit(nick=nickname)
await current_chan.send('Le troll est dans la place !') await current_chan.send('Le troll est dans la place !')
ctx = await bot.get_context(current_chan.last_message) ctx = await bot.get_context(current_chan.last_message)
join = bot.get_command('join') join = bot.get_command('join')
@ -660,7 +675,8 @@ def main():
gl_url=gl_url, gl_url=gl_url,
gl_token=gl_token, gl_token=gl_token,
gif_token=gif_token, gif_token=gif_token,
audio_path=audio_path audio_path=audio_path,
nickname=nickname,
) )
) )
bot.run(token) bot.run(token)