Python logging.py() Examples

The following are 5 code examples for showing how to use logging.py(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module logging , or try the search function .

Example 1
Project: pyquarkchain   Author: QuarkChain   File: utils.py    License: MIT License 6 votes vote down vote up
def findCaller(self, stack_info=False):
        frame = sys._getframe(2)
        f_to_skip = {
            func for func in dir(Logger) if callable(getattr(Logger, func))
        }.union({func for func in dir(QKCLogger) if callable(getattr(QKCLogger, func))})

        while frame:
            code = frame.f_code
            if _LOGGING_FILE_PREFIX not in code.co_filename and (
                "utils.py" not in code.co_filename or code.co_name not in f_to_skip
            ):
                if not stack_info:
                    return (code.co_filename, frame.f_lineno, code.co_name, "")
                else:
                    sinfo = None
                    if stack_info:
                        out = io.StringIO()
                        out.write(u"Stack (most recent call last):\n")
                        traceback.print_stack(frame, file=out)
                        sinfo = out.getvalue().rstrip(u"\n")
                    return (code.co_filename, frame.f_lineno, code.co_name, sinfo)
            frame = frame.f_back 
Example 2
Project: gtos   Author: jcyk   File: logging.py    License: MIT License 6 votes vote down vote up
def init_logger(log_name=None, log_file=None):
    """
    Adopted from OpenNMT-py:
        https://github.com/OpenNMT/OpenNMT-py/blob/master/onmt/utils/logging.py
    """
    log_format = logging.Formatter("[%(asctime)s %(levelname)s] %(message)s")
    logger = logging.getLogger(log_name)
    logger.setLevel(logging.INFO)

    console_handler = logging.StreamHandler()
    console_handler.setFormatter(log_format)
    logger.handlers = [console_handler]

    if log_file and log_file != '':
        file_handler = logging.FileHandler(log_file)
        file_handler.setFormatter(log_format)
        logger.addHandler(file_handler)

    return logger 
Example 3
Project: stog   Author: sheng-z   File: logging.py    License: MIT License 6 votes vote down vote up
def init_logger(log_name=None, log_file=None):
    """
    Adopted from OpenNMT-py:
        https://github.com/OpenNMT/OpenNMT-py/blob/master/onmt/utils/logging.py
    """
    log_format = logging.Formatter("[%(asctime)s %(levelname)s] %(message)s")
    logger = logging.getLogger(log_name)
    logger.setLevel(logging.INFO)

    console_handler = logging.StreamHandler()
    console_handler.setFormatter(log_format)
    logger.handlers = [console_handler]

    if log_file and log_file != '':
        file_handler = logging.FileHandler(log_file)
        file_handler.setFormatter(log_format)
        logger.addHandler(file_handler)

    return logger 
Example 4
Project: pyquarkchain   Author: QuarkChain   File: utils.py    License: MIT License 5 votes vote down vote up
def trace(self, msg: str, *args, **kwargs) -> None:
        """
        log as debug for now
        see https://github.com/ethereum/py-evm/blob/master/eth/tools/logging.py
        """
        self.debug(msg, *args, **kwargs) 
Example 5
Project: eva   Author: georgia-tech-db   File: logging_manager.py    License: Apache License 2.0 5 votes vote down vote up
def setEffectiveLevel(self, level: LoggingLevel):

        # Note: pytest logging level cannot be higher than WARNING
        # https://github.com/segevfiner/pytest/blob/master/
        # _pytest/logging.py#L246
        self._LOG.setLevel(level.value)