Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move instantiation of exception_formatter up
  • Loading branch information
blueyed committed Apr 9, 2019
commit cb43c842edcf95d5e87f5fddf0285ee891427814
34 changes: 17 additions & 17 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,23 @@ def filter_func(r):
"Invalid level value, it should be a positive integer, not: %d" % levelno
)

try:
encoding = sink.encoding
except AttributeError:
encoding = None

if not encoding:
encoding = "ascii"

if exception_formatter is UNSET:
exception_formatter = ExceptionFormatter(
colorize=colorize,
encoding=encoding,
diagnose=diagnose,
backtrace=backtrace,
hidden_frames_filename=self.catch.__code__.co_filename,
)

if isinstance(format, str):
formatter = format + "\n{exception}"
is_formatter_dynamic = False
Expand All @@ -755,27 +772,10 @@ def filter_func(r):
% type(format).__name__
)

try:
encoding = sink.encoding
except AttributeError:
encoding = None

if not encoding:
encoding = "ascii"

with self._lock:
handler_id = next(self._handlers_count)
colors = [lvl.color for lvl in self._levels.values()] + [""]

if exception_formatter is UNSET:
exception_formatter = ExceptionFormatter(
colorize=colorize,
encoding=encoding,
diagnose=diagnose,
backtrace=backtrace,
hidden_frames_filename=self.catch.__code__.co_filename,
)

handler = Handler(
writer=writer,
stopper=stopper,
Expand Down