本文整理汇总了Python中logzero.setup_logger方法的典型用法代码示例。如果您正苦于以下问题:Python logzero.setup_logger方法的具体用法?Python logzero.setup_logger怎么用?Python logzero.setup_logger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logzero
的用法示例。
在下文中一共展示了logzero.setup_logger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_default_logger
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def setup_default_logger(logfile=None, level=logging.DEBUG, formatter=None, maxBytes=0, backupCount=0, disableStderrLogger=False):
"""
Deprecated. Use `logzero.loglevel(..)`, `logzero.logfile(..)`, etc.
Globally reconfigures the default `logzero.logger` instance.
Usage:
.. code-block:: python
from logzero import logger, setup_default_logger
setup_default_logger(level=logging.WARN)
logger.info("hello") # this will not be displayed anymore because minimum loglevel was set to WARN
:arg string logfile: If set, also write logs to the specified filename.
:arg int level: Minimum `logging-level <https://docs.python.org/2/library/logging.html#logging-levels>`_ to display (default: `logging.DEBUG`).
:arg Formatter formatter: `Python logging Formatter object <https://docs.python.org/2/library/logging.html#formatter-objects>`_ (by default uses the internal LogFormatter).
:arg int maxBytes: Size of the logfile when rollover should occur. Defaults to 0, rollover never occurs.
:arg int backupCount: Number of backups to keep. Defaults to 0, rollover never occurs.
:arg bool disableStderrLogger: Should the default stderr logger be disabled. Defaults to False.
"""
global logger
logger = setup_logger(name=LOGZERO_DEFAULT_LOGGER, logfile=logfile, level=level, formatter=formatter, disableStderrLogger=disableStderrLogger)
return logger
示例2: test_write_to_logfile_and_stderr
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def test_write_to_logfile_and_stderr(capsys):
"""
Should log to a file.
"""
logzero.reset_default_logger()
temp = tempfile.NamedTemporaryFile()
try:
logger = logzero.setup_logger(logfile=temp.name)
logger.info("test log output")
_out, err = capsys.readouterr()
assert " test_logzero:" in err
assert err.endswith("test log output\n")
with open(temp.name) as f:
content = f.read()
assert " test_logzero:" in content
assert content.endswith("test log output\n")
finally:
temp.close()
示例3: test_custom_formatter
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def test_custom_formatter():
"""
Should work with a custom formatter.
"""
logzero.reset_default_logger()
temp = tempfile.NamedTemporaryFile()
try:
log_format = '%(color)s[%(levelname)1.1s %(asctime)s customnametest:%(lineno)d]%(end_color)s %(message)s'
formatter = logzero.LogFormatter(fmt=log_format)
logger = logzero.setup_logger(logfile=temp.name, formatter=formatter)
logger.info("test log output")
with open(temp.name) as f:
content = f.read()
assert " customnametest:" in content
assert content.endswith("test log output\n")
finally:
temp.close()
示例4: test_loglevel
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def test_loglevel():
"""
Should not log any debug messages if minimum level is set to INFO
"""
logzero.reset_default_logger()
temp = tempfile.NamedTemporaryFile()
try:
logger = logzero.setup_logger(logfile=temp.name, level=logging.INFO)
logger.debug("test log output")
with open(temp.name) as f:
content = f.read()
assert len(content.strip()) == 0
finally:
temp.close()
示例5: test_multiple_loggers_one_logfile
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def test_multiple_loggers_one_logfile():
"""
Should properly log bytes
"""
logzero.reset_default_logger()
temp = tempfile.NamedTemporaryFile()
try:
logger1 = logzero.setup_logger(name="logger1", logfile=temp.name)
logger2 = logzero.setup_logger(name="logger2", logfile=temp.name)
logger3 = logzero.setup_logger(name="logger3", logfile=temp.name)
logger1.info("logger1")
logger2.info("logger2")
logger3.info("logger3")
with open(temp.name) as f:
content = f.read().strip()
assert "logger1" in content
assert "logger2" in content
assert "logger3" in content
assert len(content.split("\n")) == 3
finally:
temp.close()
示例6: test_setup_logger_logfile_custom_loglevel
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def test_setup_logger_logfile_custom_loglevel(capsys):
"""
setup_logger(..) with filelogger and custom loglevel
"""
logzero.reset_default_logger()
temp = tempfile.NamedTemporaryFile()
try:
logger = logzero.setup_logger(logfile=temp.name, fileLoglevel=logging.WARN)
logger.info("info1")
logger.warn("warn1")
with open(temp.name) as f:
content = f.read()
assert "] info1" not in content
assert "] warn1" in content
finally:
temp.close()
示例7: setup_default_logger
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def setup_default_logger(logfile=None, level=logging.DEBUG, formatter=None, maxBytes=0, backupCount=0):
"""
Deprecated. Use `logzero.loglevel(..)`, `logzero.logfile(..)`, etc.
Globally reconfigures the default `logzero.logger` instance.
Usage:
.. code-block:: python
from logzero import logger, setup_default_logger
setup_default_logger(level=logging.WARN)
logger.info("hello") # this will not be displayed anymore because minimum loglevel was set to WARN
:arg string logfile: If set, also write logs to the specified filename.
:arg int level: Minimum `logging-level <https://docs.python.org/2/library/logging.html#logging-levels>`_ to display (default: `logging.DEBUG`).
:arg Formatter formatter: `Python logging Formatter object <https://docs.python.org/2/library/logging.html#formatter-objects>`_ (by default uses the internal LogFormatter).
:arg int maxBytes: Size of the logfile when rollover should occur. Defaults to 0, rollover never occurs.
:arg int backupCount: Number of backups to keep. Defaults to 0, rollover never occurs.
"""
global logger
logger = setup_logger(name=LOGZERO_DEFAULT_LOGGER, logfile=logfile, level=level, formatter=formatter)
return logger
示例8: __init__
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def __init__(self, log_file: str = None, device: str = "cpu"):
self.device = device
self.models_cache_dir = pathlib.Path(MODELS_CACHE_DIR)
if not self.models_cache_dir.is_dir():
self.models_cache_dir.mkdir(parents=True)
self.final_model_dir = self.models_cache_dir.joinpath("sectlabel_elmo_bilstm")
self.model_filepath = self.final_model_dir.joinpath("best_model.pt")
self.data_dir = pathlib.Path(DATA_DIR)
if not self.data_dir.is_dir():
self.data_dir.mkdir(parents=True)
self.train_data_url = DATA_FILE_URLS["SECT_LABEL_TRAIN_FILE"]
self.dev_data_url = DATA_FILE_URLS["SECT_LABEL_DEV_FILE"]
self.test_data_url = DATA_FILE_URLS["SECT_LABEL_TEST_FILE"]
self.msg_printer = wasabi.Printer()
self._download_if_required()
self.data_manager = self._get_data()
self.hparams = self._get_hparams()
self.model = self._get_model()
self.infer = self._get_infer_client()
self.log_file = log_file
if log_file:
self.logger = setup_logger(
"sectlabel_logger", logfile=self.log_file, level=logging.INFO
)
else:
self.logger = self.msg_printer
示例9: __init__
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def __init__(self, d: "uiautomator2.Device"):
"""
Args:
d (uiautomator2 instance)
"""
self.logger = setup_logger()
self._d = d
assert hasattr(d, 'click')
assert hasattr(d, 'screenshot')
self.logger.setLevel(logging.DEBUG)
示例10: __init__
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def __init__(self, d: "uiautomator2.Device"):
"""
Args:
d (uiautomator2 instance)
"""
self._d = d
assert hasattr(d, "click")
assert hasattr(d, "swipe")
assert hasattr(d, "window_size")
assert hasattr(d, "dump_hierarchy")
assert hasattr(d, "screenshot")
assert hasattr(d, 'wait_timeout')
self._click_before_delay = 0.0 # pre delay
self._click_after_delay = None # post delay
self._last_source = None
self._event_callbacks = defaultdict(list)
# used for click("#back") and back is the key
self._alias = {}
self._alias_strict = False
self._dump_lock = threading.Lock()
# 这里setup_logger不可以通过level参数传入logging.INFO
# 不然其StreamHandler都要重新setLevel,没看懂也没关系,反正就是不要这么干. 特此备注
self._logger = setup_logger()
self._logger.setLevel(logging.INFO)
示例11: __init__
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def __init__(self, d: "uiautomator2.Device"):
self._d = d
self._watchers = []
self._watch_stop_event = threading.Event()
self._watch_stopped = threading.Event()
self._watching = False # func start is calling
self._triggering = False
self.logger = setup_logger()
self.logger.setLevel(logging.INFO)
示例12: __init__
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def __init__(self, d: "u2.Device"):
self._d = d
self._widgets = {}
self._compare_results = {}
self.popups = []
self.logger = setup_logger()
self.logger.setLevel(logging.INFO)
示例13: __init__
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def __init__(self, device: adbutils.AdbDevice, loglevel=logging.INFO):
d = self._device = device
self.sdk = d.getprop('ro.build.version.sdk')
self.abi = d.getprop('ro.product.cpu.abi')
self.pre = d.getprop('ro.build.version.preview_sdk')
self.arch = d.getprop('ro.arch')
self.abis = (d.getprop('ro.product.cpu.abilist').strip()
or self.abi).split(",")
self.server_addr = None
self.logger = setup_logger(level=loglevel)
# self.logger.debug("Initial device %s", device)
self.logger.info("uiautomator2 version: %s", __version__)
示例14: reset_default_logger
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def reset_default_logger():
"""
Resets the internal default logger to the initial configuration
"""
global logger
global _loglevel
global _logfile
global _formatter
_loglevel = logging.DEBUG
_logfile = None
_formatter = None
logger = setup_logger(name=LOGZERO_DEFAULT_LOGGER, logfile=_logfile, level=_loglevel, formatter=_formatter)
# Initially setup the default logger
示例15: setup_logger
# 需要导入模块: import logzero [as 别名]
# 或者: from logzero import setup_logger [as 别名]
def setup_logger(name=None, logfile=None, level=logging.DEBUG, formatter=None, maxBytes=0, backupCount=0, fileLoglevel=None):
"""
Configures and returns a fully configured logger instance, no hassles.
If a logger with the specified name already exists, it returns the existing instance,
else creates a new one.
If you set the ``logfile`` parameter with a filename, the logger will save the messages to the logfile,
but does not rotate by default. If you want to enable log rotation, set both ``maxBytes`` and ``backupCount``.
Usage:
.. code-block:: python
from logzero import setup_logger
logger = setup_logger()
logger.info("hello")
:arg string name: Name of the `Logger object <https://docs.python.org/2/library/logging.html#logger-objects>`_. Multiple calls to ``setup_logger()`` with the same name will always return a reference to the same Logger object. (defaut: ``__name__``)
:arg string logfile: If set, also write logs to the specified filename.
:arg int level: Minimum `logging-level <https://docs.python.org/2/library/logging.html#logging-levels>`_ to display (default: ``logging.DEBUG``).
:arg Formatter formatter: `Python logging Formatter object <https://docs.python.org/2/library/logging.html#formatter-objects>`_ (by default uses the internal LogFormatter).
:arg int maxBytes: Size of the logfile when rollover should occur. Defaults to 0, rollover never occurs.
:arg int backupCount: Number of backups to keep. Defaults to 0, rollover never occurs.
:arg int fileLoglevel: Minimum `logging-level <https://docs.python.org/2/library/logging.html#logging-levels>`_ for the file logger (is not set, it will use the loglevel from the ``level`` argument)
:return: A fully configured Python logging `Logger object <https://docs.python.org/2/library/logging.html#logger-objects>`_ you can use with ``.debug("msg")``, etc.
"""
_logger = logging.getLogger(name or __name__)
_logger.propagate = False
_logger.setLevel(level)
# Reconfigure existing handlers
has_stream_handler = False
for handler in list(_logger.handlers):
if isinstance(handler, logging.StreamHandler):
has_stream_handler = True
if isinstance(handler, logging.FileHandler) and hasattr(handler, LOGZERO_INTERNAL_LOGGER_ATTR):
# Internal FileHandler needs to be removed and re-setup to be able
# to set a new logfile.
_logger.removeHandler(handler)
continue
# reconfigure handler
handler.setLevel(level)
handler.setFormatter(formatter or LogFormatter())
if not has_stream_handler:
stream_handler = logging.StreamHandler()
setattr(stream_handler, LOGZERO_INTERNAL_LOGGER_ATTR, True)
stream_handler.setLevel(level)
stream_handler.setFormatter(formatter or LogFormatter())
_logger.addHandler(stream_handler)
if logfile:
rotating_filehandler = RotatingFileHandler(filename=logfile, maxBytes=maxBytes, backupCount=backupCount)
setattr(rotating_filehandler, LOGZERO_INTERNAL_LOGGER_ATTR, True)
rotating_filehandler.setLevel(fileLoglevel or level)
rotating_filehandler.setFormatter(formatter or LogFormatter(color=False))
_logger.addHandler(rotating_filehandler)
return _logger