Skip to content
This repository has been archived by the owner on Jul 10, 2021. It is now read-only.

Commit

Permalink
✨feature: add create_logger.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yupix committed Dec 6, 2020
1 parent 9b1d95f commit 2145c8f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cogs/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import mysql
from discord.ext import commands

from main import logger, Output_wav_name, check_variable, db_insert, db_reformat, db_search, embed_send, db_delete, check_args
from main import Output_wav_name, check_variable, db_insert, db_reformat, db_search, embed_send, db_delete, check_args

import logging
from logging import getLogger, StreamHandler, Formatter

class NoteCog(commands.Cog):

Expand All @@ -18,6 +21,7 @@ def __init__(self, bot):
@commands.group()
async def note(self, ctx):
if ctx.invoked_subcommand is None:
logger.debug('test')
await ctx.send('このコマンドには引数が必要です')

@note.command(name='add')
Expand Down
1 change: 1 addition & 0 deletions modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from modules import create_logger, voice_generator
52 changes: 52 additions & 0 deletions modules/create_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import coloredlogs
from logging import getLogger, StreamHandler, DEBUG, Formatter, addLevelName

"""create easy logger"""

class easy_logger:
def create(self, logger):
"""create logger"""
# loggerのログレベル設定(ハンドラに渡すエラーメッセージのレベル)
logger.setLevel(DEBUG)

# --------------------------------
# 2.handlerの設定
# --------------------------------
# handlerの生成
stream_handler = StreamHandler()

# handlerのログレベル設定(ハンドラが出力するエラーメッセージのレベル)
stream_handler.setLevel(DEBUG)

# --------------------------------
# 3.loggerにhandlerをセット
# --------------------------------
logger.addHandler(stream_handler)
logger.propagate = False

coloredlogs.CAN_USE_BOLD_FONT = True
coloredlogs.DEFAULT_FIELD_STYLES = {'asctime': {'color': 'green'},
'hostname': {'color': 'magenta'},
'levelname': {'color': 'black', 'bold': True},
'name': {'color': 'blue'},
'programname': {'color': 'cyan'}
}
coloredlogs.DEFAULT_LEVEL_STYLES = {'critical': {'color': 'red', 'bold': True},
'error': {'color': 'red'},
'warning': {'color': 'yellow'},
'notice': {'color': 'magenta'},
'info': {'color': 'green'},
'debug': {},
'spam': {'color': 'green', 'faint': True},
'success': {'color': 'green', 'bold': True},
'verbose': {'color': 'blue'}
}

coloredlogs.install(level='DEBUG', logger=logger, fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%Y/%m/%d %H:%M:%S')

# SUCCESSを追加
logger.SUCCESS = 25 # WARNINGとINFOの間
addLevelName(logger.SUCCESS, 'SUCCESS')
setattr(logger, 'success', lambda message, *args: logger._log(logger.SUCCESS, message, args))
return logger
easy_logger = easy_logger()

0 comments on commit 2145c8f

Please sign in to comment.