Skip to content

Commit

Permalink
Change "opt()" to not preserve attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Dec 6, 2018
1 parent d62ec8e commit 2b8e6f9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 22 deletions.
2 changes: 1 addition & 1 deletion loguru/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

__version__ = "0.0.1"

logger = _Logger()
logger = _Logger({}, False, False, False)

if _constants.LOGURU_AUTOINIT and _sys.stderr:
logger.start(_sys.stderr)
Expand Down
11 changes: 3 additions & 8 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,15 @@ class Logger:

_lock = threading.Lock()

def __init__(self, *, extra={}, record=False, exception=None, lazy=False):
def __init__(self, extra, exception, record, lazy):
self.catch = Catcher(self)
self.extra = extra
self._record = record
self._exception = exception
self._lazy = lazy

def opt(self, exception=None, record=None, lazy=None):
extra = self.extra.copy()
exception = self._exception if exception is None else exception
record = self._record if record is None else record
lazy = self._lazy if lazy is None else lazy
logger = Logger(extra=extra, exception=exception, record=record, lazy=lazy)
return logger
def opt(self, *, exception=False, record=False, lazy=False):
return Logger(self.extra, exception, record, lazy)

def bind(self, **kwargs):
extra = {**self.extra, **kwargs}
Expand Down
13 changes: 0 additions & 13 deletions tests/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,6 @@ def test_keep_extra(writer):

assert writer.read() == "123\n"

def test_keep_others(writer):
logger.start(writer, format='{message}')
logger.opt(record=True).opt().debug("{record[level].name}")
logger.debug("{record}", record=123)
try:
1 / 0
except:
logger.opt(record=True).opt(exception=True).debug("{record[level].no}")

result = writer.read().strip()
assert result.startswith("DEBUG\n123\n10\n")
assert result.endswith("ZeroDivisionError: division by zero")

def test_before_bind(writer):
logger.start(writer, format='{message}')
logger.opt(record=True).bind(key="value").info("{record[level]}")
Expand Down

0 comments on commit 2b8e6f9

Please sign in to comment.