Skip to content

Commit 686f1ca

Browse files
committed
logging: Move exc_info to common log.
The keyword parameters are populated to common log and exc_info should be common to all methods anyway. This change the default to be exc_info=False for all cases similar to the standard python. Signed-off-by: Alon Bar-Lev <[email protected]>
1 parent 6451d26 commit 686f1ca

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

python-stdlib/logging/logging.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def isEnabledFor(self, level):
125125
def getEffectiveLevel(self):
126126
return self.level or getLogger().level or _DEFAULT_LEVEL
127127

128-
def log(self, level, msg, *args, extra=None):
128+
def log(self, level, msg, *args, exc_info=False, extra=None):
129129
if self.isEnabledFor(level):
130130
if args:
131131
if isinstance(args[0], dict):
@@ -138,6 +138,16 @@ def log(self, level, msg, *args, extra=None):
138138
for h in handlers:
139139
h.emit(record)
140140

141+
tb = None
142+
if isinstance(exc_info, BaseException):
143+
tb = exc_info
144+
elif hasattr(sys, "exc_info"):
145+
tb = sys.exc_info()[1]
146+
if tb:
147+
buf = io.StringIO()
148+
sys.print_exception(tb, buf)
149+
self.log(ERROR, buf.getvalue())
150+
141151
def debug(self, msg, *args, **kwargs):
142152
self.log(DEBUG, msg, *args, **kwargs)
143153

@@ -153,17 +163,8 @@ def error(self, msg, *args, **kwargs):
153163
def critical(self, msg, *args, **kwargs):
154164
self.log(CRITICAL, msg, *args, **kwargs)
155165

156-
def exception(self, msg, *args, exc_info=True, **kwargs):
166+
def exception(self, msg, *args, **kwargs):
157167
self.log(ERROR, msg, *args, **kwargs)
158-
tb = None
159-
if isinstance(exc_info, BaseException):
160-
tb = exc_info
161-
elif hasattr(sys, "exc_info"):
162-
tb = sys.exc_info()[1]
163-
if tb:
164-
buf = io.StringIO()
165-
sys.print_exception(tb, buf)
166-
self.log(ERROR, buf.getvalue())
167168

168169
def addHandler(self, handler):
169170
self.handlers.append(handler)

0 commit comments

Comments
 (0)