# -*- coding: utf-8 -*-
#
# This file is part of FatBotSlim.
#
# FatBotSlim is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FatBotSlim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FatBotSlim. If not, see <http://www.gnu.org/licenses/>.
#
"""
.. module:: fatbotslim.log
.. moduleauthor:: Mathieu D. (MatToufoutu)
This module contains everything useful to enable logging.
"""
import logging
LOG_FORMAT = '%(levelname)s [%(name)s] %(asctime)s - %(message)s'
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
[docs]def create_logger(name, level='INFO'):
"""
Creates a new ready-to-use logger.
:param name: new logger's name
:type name: str
:param level: default logging level.
:type level: :class:`str` or :class:`int`
:return: new logger.
:rtype: :class:`logging.Logger`
"""
formatter = ColorFormatter(LOG_FORMAT, DATE_FORMAT)
if not isinstance(logging.getLevelName(level), int):
level = 'INFO'
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger = logging.getLogger(name)
logger.setLevel(level)
logger.addHandler(handler)
return logger