mirror of
https://github.com/borgbackup/borg.git
synced 2026-04-15 21:59:58 -04:00
fix all logger pep8 warnings except long lines
This commit is contained in:
parent
8075a139b3
commit
a42a5e3e2d
2 changed files with 13 additions and 5 deletions
|
|
@ -35,6 +35,7 @@ import inspect
|
|||
import logging
|
||||
import sys
|
||||
|
||||
|
||||
def setup_logging(args, stream=None):
|
||||
"""setup logging module according to the arguments provided
|
||||
|
||||
|
|
@ -46,16 +47,18 @@ def setup_logging(args, stream=None):
|
|||
sh = logging.StreamHandler(stream)
|
||||
# other formatters will probably want this, but let's remove
|
||||
# clutter on stderr
|
||||
#sh.setFormatter(logging.Formatter('%(name)s: %(message)s'))
|
||||
# example:
|
||||
# sh.setFormatter(logging.Formatter('%(name)s: %(message)s'))
|
||||
l.addHandler(sh)
|
||||
levels = { None: logging.WARNING,
|
||||
0: logging.WARNING,
|
||||
1: logging.INFO,
|
||||
2: logging.DEBUG }
|
||||
levels = {None: logging.WARNING,
|
||||
0: logging.WARNING,
|
||||
1: logging.INFO,
|
||||
2: logging.DEBUG}
|
||||
# default to WARNING, -v goes to INFO and -vv to DEBUG
|
||||
l.setLevel(levels[args.verbose])
|
||||
return sh,
|
||||
|
||||
|
||||
def find_parent_module():
|
||||
"""find the name of a the first module calling this module
|
||||
|
||||
|
|
@ -74,6 +77,7 @@ def find_parent_module():
|
|||
# return the logger module name by default
|
||||
return __name__
|
||||
|
||||
|
||||
def create_logger(name=None):
|
||||
"""create a Logger object with the proper path, which is returned by
|
||||
find_parent_module() by default, or is provided via the commandline
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import pytest
|
|||
from ..logger import find_parent_module, create_logger, setup_logging
|
||||
logger = create_logger()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def io_logger():
|
||||
io = StringIO()
|
||||
|
|
@ -22,10 +23,12 @@ def io_logger():
|
|||
logger.setLevel(logging.DEBUG)
|
||||
return io
|
||||
|
||||
|
||||
def test_setup_logging(io_logger):
|
||||
logger.info('hello world')
|
||||
assert io_logger.getvalue() == "borg.testsuite.logger: hello world\n"
|
||||
|
||||
|
||||
def test_multiple_loggers(io_logger):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info('hello world 1')
|
||||
|
|
@ -39,5 +42,6 @@ def test_multiple_loggers(io_logger):
|
|||
logger.info('hello world 2')
|
||||
assert io_logger.getvalue() == "borg.testsuite.logger: hello world 2\n"
|
||||
|
||||
|
||||
def test_parent_module():
|
||||
assert find_parent_module() == __name__
|
||||
|
|
|
|||
Loading…
Reference in a new issue