Python loguru.logger.critical() Examples

The following are 6 code examples of loguru.logger.critical(). 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 also want to check out all available functions/classes of the module loguru.logger , or try the search function .
Example #1
Source File: Base_Logging.py    From makemework with MIT License 6 votes vote down vote up
def write(self,msg,level='info'):
        "Write out a message"
        fname = inspect.stack()[2][3] #May be use a entry-exit decorator instead        
        d = {'caller_func': fname}                    
        if level.lower()== 'debug': 
            logger.debug("{module} | {msg}",module=d['caller_func'],msg=msg)                      
        elif level.lower()== 'info':
            logger.info("{module} | {msg}",module=d['caller_func'],msg=msg)           
        elif level.lower()== 'warn' or level.lower()=='warning':           
            logger.warning("{module} | {msg}",module=d['caller_func'],msg=msg)
        elif level.lower()== 'error':
            logger.error("{module} | {msg}",module=d['caller_func'],msg=msg)            
        elif level.lower()== 'critical':   
            logger.critical("{module} | {msg}",module=d['caller_func'],msg=msg)            
        else:
            logger.critical("Unknown level passed for the msg: {}", msg) 
Example #2
Source File: run.py    From ScaffoldGraph with MIT License 6 votes vote down vote up
def scaffoldgraph_main():
    """Run the CLI utility for ScaffoldGraph."""
    parser = scaffoldgraph_args()
    args = parser.parse_args(None if sys.argv[1:] else ['-h'])
    configure_logger(args.verbosity)
    try:
        args.func(args)
    except FileNotFoundError as e:
        logger.critical(f'Input file not found: {e.filename}')
    except ValueError as e:
        logger.critical(e)
    except RuntimeError as e:
        logger.critical(e)
    except MemoryError as e:
        logger.critical(e)
    except KeyboardInterrupt:
        logger.critical('scaffoldgraph process interrupted from keyboard')
    except Exception as e:
        logger.critical(f'Unknown error: {e}')
    finally:
        logger.info('Exiting scaffoldgraph...') 
Example #3
Source File: Base_Logging.py    From qxf2-page-object-model with MIT License 5 votes vote down vote up
def write(self,msg,level='info'):
        "Write out a message"
        #fname = inspect.stack()[2][3] #May be use a entry-exit decorator instead
        all_stack_frames = inspect.stack()
        for stack_frame in all_stack_frames[1:]:
            if 'Base_Page' not in stack_frame[1]:
                break
        fname = stack_frame[3]
        d = {'caller_func': fname}
        if hasattr(pytest,'config'):
            if pytest.config._config.getoption('--reportportal'):
                rp_logger = self.setup_rp_logging()
                if level.lower()== 'debug':
                    rp_logger.debug(msg=msg)
                elif level.lower()== 'info':
                    rp_logger.info(msg)
                elif level.lower()== 'warn' or level.lower()=='warning':
                    rp_logger.warning(msg)
                elif level.lower()== 'error':
                    rp_logger.error(msg)
                elif level.lower()== 'critical':
                    rp_logger.critical(msg)
                else:
                    rp_logger.critical(msg)
                return

        if level.lower()== 'debug':
            logger.debug("{module} | {msg}",module=d['caller_func'],msg=msg)
        elif level.lower()== 'info':
            logger.info("{module} | {msg}",module=d['caller_func'],msg=msg)
        elif level.lower()== 'warn' or level.lower()=='warning':
            logger.warning("{module} | {msg}",module=d['caller_func'],msg=msg)
        elif level.lower()== 'error':
            logger.error("{module} | {msg}",module=d['caller_func'],msg=msg)
        elif level.lower()== 'critical':
            logger.critical("{module} | {msg}",module=d['caller_func'],msg=msg)
        else:
            logger.critical("Unknown level passed for the msg: {}", msg) 
Example #4
Source File: handlers.py    From veros with MIT License 5 votes vote down vote up
def signals_to_exception(signals=(signal.SIGINT, signal.SIGTERM)):
    """Context manager that makes sure that converts system signals to exceptions.

    This allows for a graceful exit after receiving SIGTERM (e.g. through
    `kill` on UNIX systems).

    Example:
       >>> with signals_to_exception():
       >>>     try:
       >>>         # do something
       >>>     except SystemExit:
       >>>         # graceful exit even upon receiving interrupt signal
    """
    def signal_to_exception(sig, frame):
        logger.critical('Received interrupt signal {}', sig)
        raise SystemExit('Aborted')

    old_signals = {}
    for s in signals:
        # override signals with our handler
        old_signals[s] = signal.getsignal(s)
        signal.signal(s, signal_to_exception)

    try:
        yield

    finally:
        # re-attach old signals
        for s in signals:
            signal.signal(s, old_signals[s]) 
Example #5
Source File: test_pickling.py    From loguru with MIT License 5 votes vote down vote up
def test_pickling_logging_method(capsys):
    logger.add(print_, format="{level} - {function} - {message}")
    pickled = pickle.dumps(logger.critical)
    func = pickle.loads(pickled)
    func("A message")
    out, err = capsys.readouterr()
    assert out == "CRITICAL - test_pickling_logging_method - A message\n"
    assert err == "" 
Example #6
Source File: mycoursesdownloader.py    From MyCoursesDownloader with MIT License 5 votes vote down vote up
def get_xfrs_token(page_html):
    """
    Method to parse a D2L page to find the XSRF.Token. The token is returned as a string
    :param page_html:
    :return:
    """
    soup = BeautifulSoup(page_html, "html.parser")
    # TODO Loop over all of them, as the location might change
    xsrf = str(soup.findAll("script")[0]).splitlines()
    token = None

    for line in xsrf:
        if "XSRF.Token" in line:  #
            line_soup = re.findall("'(.*?)'", line)
            # We can also find our User.ID in this line as well
            for i in range(0, len(line_soup)):
                if line_soup[i] == 'XSRF.Token':
                    token = line_soup[i + 1]
                    break

    if token is None:
        logger.critical("Cannot find XSRF.Token. Code might have changed")
        exit(1)
    logger.debug("Found XSRF.Token. It's {}".format(token))

    return token