Mercurial > p > roundup > code
comparison roundup/admin.py @ 8446:14c7c07b32d8
feature: add thread local trace_id and trace_reason to logging.
Added trace_id to default logging so that all logs for a given request
share the same trace_id.
This allows correlation of logs across a request.
admin_guide.txt, upgrading.txt:
add docs
update sample configs to include trace_id.
rewrite logging docs in admin_guide. Hopefully they are clearer now.
clean up some stuff in the logging config file docs.
admin.py:
add decorators to run_command to enable trace_id.
change calls to db.commit() to use run_command to get trace_id.
configuration.py:
clean up imports.
update docstrings, comments and inline docs.
add trace_id to default log format.
add function for testing decorated with trace_id.
add support for dumping stack trace in logging.
add check for pytest in sys.modules to enable log propagation when
pytest is running. Otherwise tests fail as the caplog logger doesn't
see the roundup logs.
logcontext.py:
new file to handle thread local contextvar mangement.
mailgw.py:
add decorators for trace_id etc.
scripts/roundup_xlmrpc_server.py:
add decorators for trace_id etc.
fix encoding bug turning bytes into a string.
fix command line issue where we can't set encoding. (not sure if
changing encoding via command line even works)
cgi/client.py
decorate two entry points for trace_id etc.
cgi/wsgi_handler.py:
decorate entry point for trace_id etc.
test/test_config.py:
add test for trace_id in new log format.
test various cases for sinfo and errors in formating msg.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 16 Sep 2025 22:53:00 -0400 |
| parents | 254f70dfc585 |
| children | 224ccb8b49ca |
comparison
equal
deleted
inserted
replaced
| 8445:4b6e9a0e13ee | 8446:14c7c07b32d8 |
|---|---|
| 47 ParsingOptionError, | 47 ParsingOptionError, |
| 48 UserConfig, | 48 UserConfig, |
| 49 ) | 49 ) |
| 50 from roundup.exceptions import UsageError | 50 from roundup.exceptions import UsageError |
| 51 from roundup.i18n import _, get_translation | 51 from roundup.i18n import _, get_translation |
| 52 from roundup.logcontext import gen_trace_id, store_trace_reason | |
| 52 | 53 |
| 53 try: | 54 try: |
| 54 from UserDict import UserDict | 55 from UserDict import UserDict |
| 55 except ImportError: | 56 except ImportError: |
| 56 from collections import UserDict | 57 from collections import UserDict |
| 2352 print(_('Error: %s') % message) | 2353 print(_('Error: %s') % message) |
| 2353 print() | 2354 print() |
| 2354 print(function.__doc__) | 2355 print(function.__doc__) |
| 2355 return 1 | 2356 return 1 |
| 2356 | 2357 |
| 2358 @gen_trace_id() | |
| 2359 @store_trace_reason('admin') | |
| 2357 def run_command(self, args): | 2360 def run_command(self, args): |
| 2358 """Run a single command | 2361 """Run a single command |
| 2359 """ | 2362 """ |
| 2360 command = args[0] | 2363 command = args[0] |
| 2361 | 2364 |
| 2597 | 2600 |
| 2598 # exit.. check for transactions | 2601 # exit.. check for transactions |
| 2599 if self.db and self.db_uncommitted: | 2602 if self.db and self.db_uncommitted: |
| 2600 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? ')) | 2603 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? ')) |
| 2601 if commit and commit[0].lower() == 'y': | 2604 if commit and commit[0].lower() == 'y': |
| 2602 self.db.commit() | 2605 self.run_command(["commit"]) |
| 2603 | 2606 |
| 2604 # looks like histfile is saved with mode 600 | 2607 # looks like histfile is saved with mode 600 |
| 2605 if self.readline and self.history_features('save_history'): | 2608 if self.readline and self.history_features('save_history'): |
| 2606 self.readline.write_history_file(histfile) | 2609 self.readline.write_history_file(histfile) |
| 2607 | 2610 |
| 2672 try: | 2675 try: |
| 2673 if not args: | 2676 if not args: |
| 2674 self.interactive() | 2677 self.interactive() |
| 2675 else: | 2678 else: |
| 2676 ret = self.run_command(args) | 2679 ret = self.run_command(args) |
| 2677 if self.db: self.db.commit() # noqa: E701 | 2680 if self.db: self.run_command(["commit"]) # noqa: E701 |
| 2678 return ret | 2681 return ret |
| 2679 finally: | 2682 finally: |
| 2680 if self.db: | 2683 if self.db: |
| 2681 self.db.close() | 2684 self.db.close() |
| 2682 | 2685 |
