Skip to content

Commit

Permalink
Merge pull request #742 from reef-technologies/rel3.0.1
Browse files Browse the repository at this point in the history
logging fix and release 3.0.1
  • Loading branch information
ppolewicz committed Aug 9, 2021
2 parents 8be19c0 + 490c1bc commit fd855c9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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(),
Expand Down
26 changes: 17 additions & 9 deletions test/integration/test_b2_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit fd855c9

Please sign in to comment.