Merge pull request #197 from MightyCreak/better-log-stacktrace
feat: improve log stack trace
This commit is contained in:
commit
61f65fb826
|
@ -1,3 +1,4 @@
|
||||||
[mypy]
|
[mypy]
|
||||||
warn_unused_ignores = True
|
warn_unused_ignores = True
|
||||||
disallow_incomplete_defs = True
|
disallow_incomplete_defs = True
|
||||||
|
disable_error_code = annotation-unchecked
|
||||||
|
|
|
@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Remove log function calls from the stack trace when calling `logDebug` or
|
||||||
|
`logError` (@MightyCreak)
|
||||||
|
- Log functions used to log only on stderr, now `logDebug` logs on stdout and
|
||||||
|
`logError` logs on stderr (@MightyCreak)
|
||||||
|
|
||||||
## 0.8.0 - 2023-04-03
|
## 0.8.0 - 2023-04-03
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
import inspect
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import locale
|
import locale
|
||||||
|
@ -82,11 +83,15 @@ def isWindows() -> bool:
|
||||||
return os.name == 'nt'
|
return os.name == 'nt'
|
||||||
|
|
||||||
|
|
||||||
def _logPrintOutput(msg: str) -> None:
|
def _logPrintOutput(msg: str, file: Optional[TextIO] = None) -> None:
|
||||||
if theResources.getOptionAsBool('log_print_output'):
|
if theResources.getOptionAsBool('log_print_output'):
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=file)
|
||||||
if theResources.getOptionAsBool('log_print_stack'):
|
if theResources.getOptionAsBool('log_print_stack'):
|
||||||
traceback.print_stack()
|
# Show the stack trace, but remove the past 2 calls as it is just log functions noise
|
||||||
|
frames = inspect.stack()
|
||||||
|
frameIdx = min(2, len(frames) - 1)
|
||||||
|
print('Traceback (most recent call last):', file=file)
|
||||||
|
traceback.print_stack(frames[frameIdx].frame, file=file)
|
||||||
|
|
||||||
|
|
||||||
def logDebug(msg: str) -> None:
|
def logDebug(msg: str) -> None:
|
||||||
|
@ -96,7 +101,7 @@ def logDebug(msg: str) -> None:
|
||||||
|
|
||||||
def logError(msg: str) -> None:
|
def logError(msg: str) -> None:
|
||||||
'''Report error message.'''
|
'''Report error message.'''
|
||||||
_logPrintOutput(f'ERROR: {msg}')
|
_logPrintOutput(f'ERROR: {msg}', sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def logErrorAndDialog(msg: str, parent: Gtk.Widget = None) -> None:
|
def logErrorAndDialog(msg: str, parent: Gtk.Widget = None) -> None:
|
||||||
|
|
Loading…
Reference in New Issue