How to use the loguru.logger.enable function in loguru

To help you get started, we’ve selected a few loguru examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Delgan / loguru / tests / test_activation.py View on Github external
def test_log_before_disable_f_globals_name_absent(writer, f_globals_name_absent):
    logger.add(writer, format="{message}")
    logger.enable(None)
    logger.debug("yes")
    logger.disable(None)
    logger.debug("nope")
    result = writer.read()
    assert result == "yes\n"
github Delgan / loguru / tests / test_activation.py View on Github external
def test_f_globals_name_absent_with_others(writer, f_globals_name_absent):
    logger.add(writer, format="{message}")
    logger.info("1")
    logger.enable(None)
    logger.disable("foobar")
    logger.enable("foo.bar")
    logger.disable(None)
    logger.info("2")
    logger.enable("foobar")
    logger.enable(None)
    logger.info("3")
    assert writer.read() == "1\n3\n"
github Delgan / loguru / tests / test_activation.py View on Github external
n = lambda: len(logger._core.activation_list)

    assert n() == 0
    logger.enable("")
    assert n() == 0
    logger.disable("")
    assert n() == 1
    logger.enable("foo")
    assert n() == 2
    logger.enable("foo.bar")
    assert n() == 2
    logger.disable("foo")
    assert n() == 1
    logger.disable("foo.bar")
    assert n() == 1
    logger.enable("foo.bar")
    assert n() == 2
    logger.disable("foo.bar.baz")
    assert n() == 3
    logger.disable("foo.baz")
    assert n() == 3
    logger.disable("foo.baz.bar")
    assert n() == 3
    logger.enable("foo.baz.bar")
    assert n() == 4
    logger.enable("")
    assert n() == 0
github Delgan / loguru / tests / test_pickling.py View on Github external
        logger.enable,
        logger.configure,
        logger.parse,
        logger.exception,
    ],
)
def test_pickling_no_error(method):
    pickled = pickle.dumps(method)
    unpickled = pickle.loads(pickled)
    assert unpickled
github pawamoy / aria2p / src / aria2p / __init__.py View on Github external
def enable_logger(sink=sys.stderr, level="WARNING"):
    """
    Enable the logging of messages.

    Configure the ``logger`` variable imported from ``loguru``.

    Args:
        sink (file): An opened file pointer, or stream handler. Default to standard error.
        level (str): The log level to use. Possible values are TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL.
            Default to WARNING.
    """
    logger.remove()
    logger.configure(handlers=[{"sink": sink, "level": level}])
    logger.enable("aria2p")
github pmrowla / pylivemaker / livemaker / cli / __init__.py View on Github external
from .lmar import lmar
from .lmgraph import lmgraph
from .lmlpb import lmlpb
from .lmlsb import lmlsb
from .lmpatch import lmpatch

__all__ = ["galconvert", "lmar", "lmbmp", "lmgraph", "lmlpb", "lmlsb", "lmpatch"]


logger.remove()

if os.name == "nt":
    sys.stdout.reconfigure(encoding="utf-8", errors="backslashreplace")

logger.add(sys.stderr, level="WARNING")
logger.enable("livemaker")
github ChenghaoMou / touchbar-lyric / touchbar_lyric / __main__.py View on Github external
choices=['Spotify', 'Music'], help='Music application')
    parser.add_argument('--minimal', default=False,
                        action='store_true', help='Remove title and artists')
    parser.add_argument('--bg', default='51,204,153', type=str,
                        help='Background color in RGB')
    parser.add_argument('--fs', default=12, type=int,
                        help='Font size')
    parser.add_argument('--fc', default='255,255,255',
                        type=str, help='Font color in RGB')
    parser.add_argument('--traditional', default=False, action='store_true', help='Convert simplified chinese to traditional chinese')                   
    parser.add_argument('--verbose', action='store_true',
                        help='Turn on debug mode', default=False)

    args = parser.parse_args()
    if args.verbose:
        logger.enable("touchbar_lyric")
        logger.enable("__main__")
    else:
        logger.disable("touchbar_lyric")
        logger.disable("__main__")
    logger.debug(args)
    main(
        app=args.app, 
        minimal=args.minimal, 
        background_color=args.bg,
        font_size=args.fs, 
        font_color=args.fc,
        traditional=args.traditional)
github team-ocean / veros / veros / logs.py View on Github external
logger.__class__.diagnostic = diagnostic

    def showwarning(message, cls, source, lineno, *args):
        logger.warning(
            '{warning}: {message} ({source}:{lineno})',
            message=message,
            warning=cls.__name__,
            source=source,
            lineno=lineno
        )

    warnings.showwarning = showwarning

    if runtime_state.proc_rank == 0:
        logger.enable('veros')
    else:
        logger.disable('veros')

    return logger.configure(**config)
github thebigmunch / google-music-scripts / src / google_music_scripts / config.py View on Github external
def configure_logging(
	modifier=0,
	*,
	username=None,
	debug=False,
	log_to_stdout=True,
	log_to_file=False
):
	logger.remove()

	if debug:
		logger.enable('audio_metadata')
		logger.enable('google_music')
		logger.enable('google_music-proto')
		logger.enable('google_music_utils')

	verbosity = 3 + modifier

	if verbosity < 0:
		verbosity = 0
	elif verbosity > 8:
		verbosity = 8

	log_level = VERBOSITY_LOG_LEVELS[verbosity]

	if log_to_stdout:
		logger.add(
			sys.stdout,
			level=log_level,
			format=LOG_FORMAT,
			backtrace=False