Skip to content

Commit

Permalink
more robust logging setup
Browse files Browse the repository at this point in the history
  • Loading branch information
adal-chiriliuc-reef committed May 2, 2024
1 parent 923c83f commit 0165468
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5375,12 +5375,13 @@ def _print_stderr(self, *args, **kwargs):
def _setup_logging(cls, args, argv):
if args.log_config and (args.verbose or args.debug_logs):
raise ValueError('Please provide either --log-config or --verbose/--debug-logs')
errors_kwarg = {'errors': 'backslashreplace'} if sys.version_info >= (3, 9) else {}
if args.log_config:
logging.config.fileConfig(args.log_config)
elif args.verbose or args.debug_logs:
# 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=[])
logging.basicConfig(level=logging.DEBUG, handlers=[], **errors_kwarg)
else:
logger.setLevel(logging.CRITICAL + 1) # No logs!
if args.verbose:
Expand All @@ -5395,7 +5396,7 @@ def _setup_logging(cls, args, argv):
'%(asctime)s\t%(process)d\t%(thread)d\t%(name)s\t%(levelname)s\t%(message)s'
)
formatter.converter = time.gmtime
handler = logging.FileHandler('b2_cli.log')
handler = logging.FileHandler('b2_cli.log', **errors_kwarg)
handler.setFormatter(formatter)

# logs from ALL loggers sent to the log file should be formatted this way
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+logging-encoding.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Escape invalid unicode characters in log messages.

0 comments on commit 0165468

Please sign in to comment.