本文整理匯總了Python中loguru.logger.opt方法的典型用法代碼示例。如果您正苦於以下問題:Python logger.opt方法的具體用法?Python logger.opt怎麽用?Python logger.opt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類loguru.logger
的用法示例。
在下文中一共展示了logger.opt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: emit
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def emit(self, record: logging.LogRecord) -> None: # pragma: no cover
# Get corresponding Loguru level if it exists
try:
level = logger.level(record.levelname).name
except ValueError:
level = str(record.levelno)
# Find caller from where originated the logged message
frame, depth = logging.currentframe(), 2
while frame.f_code.co_filename == logging.__file__: # noqa: WPS609
frame = cast(FrameType, frame.f_back)
depth += 1
logger.opt(depth=depth, exception=record.exc_info).log(
level, record.getMessage(),
)
示例2: resume
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def resume(self, downloads: List[Download]) -> List[bool]:
"""
Resume (unpause) the given downloads.
Parameters:
downloads: the list of downloads to resume.
Returns:
Success or failure of the operation for each given download.
"""
# TODO: batch/multicall candidate
result = []
for download in downloads:
try:
self.client.unpause(download.gid)
except ClientException as error:
logger.debug(f"Failed to resume download {download.gid}")
logger.opt(exception=True).trace(error)
result.append(error)
else:
result.append(True)
return result
示例3: followed_by
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def followed_by(self):
"""
List of downloads generated as the result of this download.
Returns a list of instances of [`Download`][aria2p.downloads.Download].
"""
if self._followed_by is None:
result = []
for gid in self.followed_by_ids:
try:
result.append(self.api.get_download(gid))
except ClientException as error:
logger.warning(f"Can't find download with GID {gid}, try to update download {self.gid} ({id(self)}")
logger.opt(exception=True).trace(error)
self._followed_by = result
return self._followed_by
示例4: following
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def following(self):
"""
The download this download is following.
Returns an instance of [`Download`][aria2p.downloads.Download].
"""
if not self._following:
following_id = self.following_id
if following_id:
try:
self._following = self.api.get_download(following_id)
except ClientException as error:
logger.warning(
f"Can't find download with GID {following_id}, try to update download {self.gid} ({id(self)}"
)
logger.opt(exception=True).trace(error)
self._following = None
return self._following
示例5: test_exception
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def test_exception(make_logging_logger, capsys, use_opt):
make_logging_logger("tests", StreamHandler(sys.stderr))
logger.add(PropagateHandler(), format="{message}")
try:
1 / 0
except:
if use_opt:
logger.opt(exception=True).error("Oops...")
else:
logger.exception("Oops...")
out, err = capsys.readouterr()
lines = err.strip().splitlines()
error = "ZeroDivisionError: division by zero"
assert out == ""
assert lines[0] == "Oops..."
assert lines[-1] == error
assert err.count(error) == 1
示例6: emit
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def emit(self, record):
logger_opt = logger.opt(depth=6, exception=record.exc_info)
logger_opt.log(record.levelname, record.getMessage())
示例7: emit
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def emit(self, record):
logger_opt = logger.opt(depth=6, exception=record.exc_info)
logger_opt.log(self._get_level(record), record.getMessage())
示例8: pause
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def pause(self, downloads: List[Download], force: bool = False) -> List[bool]:
"""
Remove the given downloads from the list.
Parameters:
downloads: the list of downloads to remove.
force: whether to pause immediately without contacting servers or not.
Returns:
Success or failure of the operation for each given download.
"""
# TODO: batch/multicall candidate
if force:
pause_func = self.client.force_pause
else:
pause_func = self.client.pause
result = []
for download in downloads:
try:
pause_func(download.gid)
except ClientException as error:
logger.debug(f"Failed to pause download {download.gid}")
logger.opt(exception=True).trace(error)
result.append(error)
else:
result.append(True)
return result
示例9: root_files_paths
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def root_files_paths(self):
"""
Return the unique set of directories/files for this download.
Instead of returning all the leaves like self.files,
return the relative root directories if any, and relative root files.
This property is useful when we need to list the directories and files
in order to move or copy them. We don't want to copy files one by one,
but rather entire directories at once when possible.
Examples:
# download dir is /a/b.
>>> self.files
["/a/b/c/1.txt", "/a/b/c/2.txt", "/a/b/3.txt"]
>>> self.root_files_paths
["/a/b/c", "/a/b/3.txt"]
"""
if not self._root_files_paths:
paths = []
for file in self.files:
if file.is_metadata:
continue
try:
relative_path = file.path.relative_to(self.dir)
except ValueError as error:
logger.warning(f"Can't determine file path '{file.path}' relative to '{self.dir}'")
logger.opt(exception=True).trace(error)
else:
path = self.dir / relative_path.parts[0]
if path not in paths:
paths.append(path)
self._root_files_paths = paths
return self._root_files_paths
示例10: emit
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def emit(self, record):
# Get corresponding Loguru level if it exists
try:
level = logger.level(record.levelname).name
except ValueError:
level = record.levelno
# Find caller from where originated the logged message
frame, depth = logging.currentframe(), 2
while frame.f_code.co_filename == logging.__file__:
frame = frame.f_back
depth += 1
logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage())
示例11: test_record
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def test_record(writer):
logger.add(writer, format="{message}")
logger.opt(record=True).debug("1")
logger.opt(record=True).debug("2 {record[level]}")
logger.opt(record=True).log(11, "3 {0} {a} {record[level].no}", 4, a=5)
assert writer.read() == "1\n2 DEBUG\n3 4 5 11\n"
示例12: test_record_in_kwargs_too
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def test_record_in_kwargs_too(writer):
logger.add(writer, catch=False)
with pytest.raises(TypeError, match=r"The message can't be formatted"):
logger.opt(record=True).info("Foo {record}", record=123)
示例13: test_record_not_in_extra
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def test_record_not_in_extra():
extra = None
def sink(message):
nonlocal extra
extra = message.record["extra"]
logger.add(sink, catch=False)
logger.opt(record=True).info("Test")
assert extra == {}
示例14: test_exception_boolean
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def test_exception_boolean(writer):
logger.add(writer, format="{level.name}: {message}")
try:
1 / 0
except:
logger.opt(exception=True).debug("Error {0} {record}", 1, record="test")
lines = writer.read().strip().splitlines()
assert lines[0] == "DEBUG: Error 1 test"
assert lines[-1] == "ZeroDivisionError: division by zero"
示例15: test_exception_exc_info
# 需要導入模塊: from loguru import logger [as 別名]
# 或者: from loguru.logger import opt [as 別名]
def test_exception_exc_info(writer):
logger.add(writer, format="{message}")
try:
1 / 0
except:
exc_info = sys.exc_info()
logger.opt(exception=exc_info).debug("test")
lines = writer.read().strip().splitlines()
assert lines[0] == "test"
assert lines[-1] == "ZeroDivisionError: division by zero"