Source code for beiran.log

# Beiran P2P Package Distribution Layer
# Copyright (C) 2019  Rainlab Inc & Creationline, Inc & Beiran Contributors
#
# Rainlab Inc. https://rainlab.co.jp
# Creationline, Inc. https://creationline.com">
# Beiran Contributors https://docs.beiran.io/contributors.html
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

""" Logging package for daemon """

import sys
import logging

from typing import List, Union # pylint: disable=unused-import
from beiran.config import config


[docs]def build_logger(name: str = __package__, filename: str = config.log_file, log_level: str = logging.getLevelName(config.log_level)) -> logging.Logger: """ Build logger class for module """ stdout_handler = logging.StreamHandler(sys.stdout) handlers = [stdout_handler] # type: List[Union[logging.FileHandler, logging.StreamHandler]] if filename: file_handler = logging.FileHandler(filename=filename) handlers.append(file_handler) logging.getLogger('asyncio').level = logging.WARNING logging.basicConfig( level=log_level, format='[%(asctime)s] [%(name)s] %(levelname)s - %(message)s', handlers=handlers ) return logging.getLogger(name)