diff --git a/CHANGELOG.md b/CHANGELOG.md index a1183ccee..2e5b9a602 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [3.0.1] - 2021-08-09 + +### Fixed +* logs from all loggers (in dependencies too) brought back + ## [3.0.0] - 2021-08-07 ### Added @@ -246,7 +251,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix an off-by-one issue when downloading a range of a file (affects library, but not CLI). * Better handling of some errors from the B2 service. -[Unreleased]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.0.0...HEAD +[Unreleased]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.0.1...HEAD +[3.0.1]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v3.0.0...v3.0.1 [3.0.0]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v2.5.1...v3.0.0 [2.5.1]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v2.5.0...v2.5.1 [2.5.0]: https://github.com/Backblaze/B2_Command_Line_Tool/compare/v2.4.0...v2.5.0 diff --git a/b2/console_tool.py b/b2/console_tool.py index ead152e83..7d9d5168a 100644 --- a/b2/console_tool.py +++ b/b2/console_tool.py @@ -2351,14 +2351,18 @@ def _setup_logging(cls, args, command, argv): if args.logConfig: logging.config.fileConfig(args.logConfig) elif args.verbose or args.debugLogs: - logger.setLevel(logging.DEBUG) + # set log level to DEBUG for ALL loggers (even those not belonging to B2), but without any handlers, + # those will added as needed (file and/or stderr) + logging.basicConfig(level=logging.DEBUG, handlers=[]) else: logger.setLevel(logging.CRITICAL + 1) # No logs! if args.verbose: formatter = logging.Formatter('%(levelname)s:%(name)s:%(message)s') handler = logging.StreamHandler() handler.setFormatter(formatter) - logger.addHandler(handler) + + # logs from ALL loggers sent to stderr should be formatted this way + logging.root.addHandler(handler) if args.debugLogs: formatter = logging.Formatter( '%(asctime)s\t%(process)d\t%(thread)d\t%(name)s\t%(levelname)s\t%(message)s' @@ -2367,9 +2371,10 @@ def _setup_logging(cls, args, command, argv): handler = logging.FileHandler('b2_cli.log') handler.setFormatter(formatter) - logger.addHandler(handler) + # logs from ALL loggers sent to the log file should be formatted this way + logging.root.addHandler(handler) - logger.info('// %s %s %s \\\\', SEPARATOR, VERSION.center(8), SEPARATOR) + logger.info(r'// %s %s %s \\', SEPARATOR, VERSION.center(8), SEPARATOR) logger.debug('platform is %s', platform.platform()) logger.debug( 'Python version is %s %s', platform.python_implementation(), diff --git a/test/integration/test_b2_command_line.py b/test/integration/test_b2_command_line.py index f23d126c3..9ee25ccfb 100644 --- a/test/integration/test_b2_command_line.py +++ b/test/integration/test_b2_command_line.py @@ -617,26 +617,34 @@ def basic_test(b2_tool, bucket_name): ['delete-bucket', to_be_removed_bucket_name, '--debugLogs'], re.compile(r'^ERROR: Bucket with id=\w* not found\s*$') ) - stack_trace_regex = re.compile( - r'Traceback \(most recent call last\):.*Bucket with id=\w* not found', re.DOTALL + stack_trace_in_log = r'Traceback \(most recent call last\):.*Bucket with id=\w* not found' + + # the two regexes below depend on log message from urllib3, which is not perfect, but this test needs to + # check global logging settings + stderr_regex = re.compile( + r'DEBUG:urllib3.connectionpool:.* "POST /b2api/v2/b2_delete_bucket HTTP' + r'.*' + stack_trace_in_log, + re.DOTALL, + ) + log_file_regex = re.compile( + r'urllib3.connectionpool\tDEBUG\t.* "POST /b2api/v2/b2_delete_bucket HTTP' + r'.*' + stack_trace_in_log, + re.DOTALL, ) with open('b2_cli.log', 'r') as logfile: log = logfile.read() - print(log) - assert re.search(stack_trace_regex, log), log + assert re.search(log_file_regex, log), log os.remove('b2_cli.log') - b2_tool.should_fail( - ['delete-bucket', to_be_removed_bucket_name, '--verbose'], stack_trace_regex - ) + b2_tool.should_fail(['delete-bucket', to_be_removed_bucket_name, '--verbose'], stderr_regex) assert not os.path.exists('b2_cli.log') b2_tool.should_fail( - ['delete-bucket', to_be_removed_bucket_name, '--verbose', '--debugLogs'], stack_trace_regex + ['delete-bucket', to_be_removed_bucket_name, '--verbose', '--debugLogs'], stderr_regex ) with open('b2_cli.log', 'r') as logfile: log = logfile.read() - assert re.search(stack_trace_regex, log), log + assert re.search(log_file_regex, log), log def key_restrictions_test(b2_tool, bucket_name):