logger.py 2.2 KB
Newer Older
W
add ad  
WuHaobo 已提交
1
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
W
WuHaobo 已提交
2
#
W
add ad  
WuHaobo 已提交
3 4 5
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
W
WuHaobo 已提交
6 7 8
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
W
add ad  
WuHaobo 已提交
9 10 11 12 13
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
W
WuHaobo 已提交
14
import logging
littletomatodonkey's avatar
littletomatodonkey 已提交
15
logging.basicConfig()
W
WuHaobo 已提交
16

W
add ad  
WuHaobo 已提交
17 18 19 20
DEBUG = logging.DEBUG  # 10
INFO = logging.INFO  # 20
WARN = logging.WARN  # 30
ERROR = logging.ERROR  # 40
W
WuHaobo 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71


class Logger(object):
    """
    Logger
    """

    def __init__(self, level=DEBUG):
        self.init(level)

    def init(self, level=DEBUG):
        """
        init
        """
        self._logger = logging.getLogger()
        self._logger.setLevel(level)

    def info(self, fmt, *args):
        """info"""
        self._logger.info(fmt, *args)

    def warning(self, fmt, *args):
        """warning"""
        self._logger.warning(fmt, *args)

    def error(self, fmt, *args):
        """error"""
        self._logger.error(fmt, *args)


_logger = Logger()


def init(level=DEBUG):
    """init for external"""
    _logger.init(level)


def info(fmt, *args):
    """info"""
    _logger.info(fmt, *args)


def warning(fmt, *args):
    """warn"""
    _logger.warning(fmt, *args)


def error(fmt, *args):
    """error"""
    _logger.error(fmt, *args)
W
add ad  
WuHaobo 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88


def advertisement():
    copyright = "PaddleClas is powered by PaddlePaddle !"
    info = "For more info please go to the following website."
    website = "https://github.com/PaddlePaddle/PaddleClas"
    AD_LEN = 55

    _logger.info("\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n".format(
        "=" * (AD_LEN + 4),
        "=={}==".format(copyright.center(AD_LEN)),
        "=" * (AD_LEN + 4),
        "=={}==".format(' ' * AD_LEN),
        "=={}==".format(info.center(AD_LEN)),
        "=={}==".format(' ' * AD_LEN),
        "=={}==".format(website.center(AD_LEN)),
        "=" * (AD_LEN + 4), ))