Python loguru.logger.trace() Examples

The following are 8 code examples of loguru.logger.trace(). 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: wiki.py    From seagull with MIT License 5 votes vote down vote up
def _load_file_of_url(path: str) -> str:
    """Detects if path is local or URL, loads file content

    Args:
        path (str): [description]

    Returns:
        str: [description]
    """
    if isfile(path):
        logger.trace(f"reading from file [{path}]..", end="")
        with open(path, "r") as f:
            content = f.read()
        logger.trace("ok")
    elif urlparse(path).scheme in {"ftp", "http", "https"}:
        logger.trace(f"trying to download [{path}]..", end="")
        req = urlopen(path)
        if req.getcode() != 200:
            raise ValueError(
                f"Invalid input URL request returned {req.getcode()}"
            )
        logger.trace("ok")
        content = req.read().decode("utf-8")
    else:
        raise ValueError(f"Unrecognized input path {path}")

    return content 
Example #2
Source File: state_dist.py    From veros with MIT License 5 votes vote down vote up
def gather_arrays(self, arrays):
        """Gather given variables from parent state object"""
        from .distributed import gather
        for arr in arrays:
            if not hasattr(self._vs, arr):
                continue
            self._gathered.add(arr)
            logger.trace(' Gathering {}', arr)
            gathered_arr = gather(
                self._vs,
                getattr(self._vs, arr),
                self._vs.variables[arr].dims
            )
            setattr(self, arr, gathered_arr) 
Example #3
Source File: state_dist.py    From veros with MIT License 5 votes vote down vote up
def scatter_arrays(self):
        """Sync all changes with parent state object"""
        from .distributed import scatter
        for arr in sorted(self._gathered):
            if not hasattr(self._vs, arr):
                continue
            logger.trace(' Scattering {}', arr)
            getattr(self._vs, arr)[...] = scatter(
                self._vs,
                getattr(self, arr),
                self._vs.variables[arr].dims
            ) 
Example #4
Source File: sqlite.py    From geomancer with MIT License 5 votes vote down vote up
def _load_spatialite(self, conn):
        """Load mod_spatialite or libspatialite"""

        try:
            conn.load_extension("mod_spatialite")
            logger.trace("Using mod_spatialite")
        except sqlite3.OperationalError:
            conn.load_extension("libspatialite")
            logger.trace("Using libspatialite") 
Example #5
Source File: test_propagation.py    From loguru with MIT License 5 votes vote down vote up
def test_propagate(make_logging_logger, capsys):
    logging_logger = make_logging_logger("tests", StreamHandler(sys.stderr))

    logging_logger.debug("1")
    logger.debug("2")

    logger.add(PropagateHandler(), format="{message}")

    logger.debug("3")
    logger.trace("4")

    out, err = capsys.readouterr()
    assert out == ""
    assert err == "1\n3\n" 
Example #6
Source File: test_opt.py    From loguru with MIT License 5 votes vote down vote up
def test_logging_within_lazy_function(writer):
    logger.add(writer, level=20, format="{message}")

    def laziness():
        logger.trace("Nope")
        logger.warning("Yes Warn")

    logger.opt(lazy=True).trace("No", laziness)

    assert writer.read() == ""

    logger.opt(lazy=True).info("Yes", laziness)

    assert writer.read() == "Yes Warn\nYes\n" 
Example #7
Source File: test_levels.py    From loguru with MIT License 5 votes vote down vote up
def test_updating_min_level(writer):
    logger.debug("Early exit -> no {error}", nope=None)

    a = logger.add(writer, level="DEBUG")

    with pytest.raises(KeyError):
        logger.debug("An {error} will occur!", nope=None)

    logger.trace("Early exit -> no {error}", nope=None)

    logger.add(writer, level="INFO")
    logger.remove(a)

    logger.debug("Early exit -> no {error}", nope=None) 
Example #8
Source File: core.py    From google-music-scripts with MIT License 4 votes vote down vote up
def download_songs(mm, songs, template=None):
	if not songs:
		logger.log('NORMAL', "No songs to download")
	else:
		logger.log('NORMAL', "Downloading songs from Google Music")

		if not template:
			template = Path.cwd()

		songnum = 0
		total = len(songs)
		pad = len(str(total))

		for song in songs:
			songnum += 1

			logger.trace(
				"Downloading -- {} - {} - {} ({})",
				song.get('title', "<title>"),
				song.get('artist', "<artist>"),
				song.get('album', "<album>"),
				song['id']
			)

			try:
				audio, _ = mm.download(song)
			except Exception as e:  # TODO: More specific exception.
				logger.log(
					'ACTION_FAILURE',
					"({:>{}}/{}) Failed -- {} | {}",
					songnum,
					pad,
					total,
					song,
					e
				)
			else:
				tags = audio_metadata.loads(audio).tags
				filepath = gm_utils.template_to_filepath(template, tags).with_suffix('.mp3')
				if filepath.is_file():
					filepath.unlink()

				filepath.parent.mkdir(parents=True, exist_ok=True)
				filepath.touch()
				filepath.write_bytes(audio)

				logger.log(
					'ACTION_SUCCESS',
					"({:>{}}/{}) Downloaded -- {} ({})",
					songnum,
					pad,
					total,
					filepath,
					song['id']
				)