borgmatic.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. import collections
  2. import json
  3. import logging
  4. import os
  5. import sys
  6. import time
  7. from queue import Queue
  8. from subprocess import CalledProcessError
  9. import colorama
  10. import pkg_resources
  11. import borgmatic.actions.borg
  12. import borgmatic.actions.break_lock
  13. import borgmatic.actions.check
  14. import borgmatic.actions.compact
  15. import borgmatic.actions.create
  16. import borgmatic.actions.export_tar
  17. import borgmatic.actions.extract
  18. import borgmatic.actions.info
  19. import borgmatic.actions.list
  20. import borgmatic.actions.mount
  21. import borgmatic.actions.prune
  22. import borgmatic.actions.rcreate
  23. import borgmatic.actions.restore
  24. import borgmatic.actions.rinfo
  25. import borgmatic.actions.rlist
  26. import borgmatic.actions.transfer
  27. import borgmatic.commands.completion
  28. from borgmatic.borg import umount as borg_umount
  29. from borgmatic.borg import version as borg_version
  30. from borgmatic.commands.arguments import parse_arguments
  31. from borgmatic.config import checks, collect, convert, validate
  32. from borgmatic.hooks import command, dispatch, monitor
  33. from borgmatic.logger import add_custom_log_levels, configure_logging, should_do_markup
  34. from borgmatic.signals import configure_signals
  35. from borgmatic.verbosity import verbosity_to_log_level
  36. logger = logging.getLogger(__name__)
  37. LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
  38. def run_configuration(config_filename, config, arguments):
  39. '''
  40. Given a config filename, the corresponding parsed config dict, and command-line arguments as a
  41. dict from subparser name to a namespace of parsed arguments, execute the defined create, prune,
  42. compact, check, and/or other actions.
  43. Yield a combination of:
  44. * JSON output strings from successfully executing any actions that produce JSON
  45. * logging.LogRecord instances containing errors from any actions or backup hooks that fail
  46. '''
  47. (location, storage, retention, consistency, hooks) = (
  48. config.get(section_name, {})
  49. for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks')
  50. )
  51. global_arguments = arguments['global']
  52. local_path = location.get('local_path', 'borg')
  53. remote_path = location.get('remote_path')
  54. retries = storage.get('retries', 0)
  55. retry_wait = storage.get('retry_wait', 0)
  56. encountered_error = None
  57. error_repository = ''
  58. using_primary_action = {'create', 'prune', 'compact', 'check'}.intersection(arguments)
  59. monitoring_log_level = verbosity_to_log_level(global_arguments.monitoring_verbosity)
  60. try:
  61. local_borg_version = borg_version.local_borg_version(storage, local_path)
  62. except (OSError, CalledProcessError, ValueError) as error:
  63. yield from log_error_records(f'{config_filename}: Error getting local Borg version', error)
  64. return
  65. try:
  66. if using_primary_action:
  67. dispatch.call_hooks(
  68. 'initialize_monitor',
  69. hooks,
  70. config_filename,
  71. monitor.MONITOR_HOOK_NAMES,
  72. monitoring_log_level,
  73. global_arguments.dry_run,
  74. )
  75. if using_primary_action:
  76. dispatch.call_hooks(
  77. 'ping_monitor',
  78. hooks,
  79. config_filename,
  80. monitor.MONITOR_HOOK_NAMES,
  81. monitor.State.START,
  82. monitoring_log_level,
  83. global_arguments.dry_run,
  84. )
  85. except (OSError, CalledProcessError) as error:
  86. if command.considered_soft_failure(config_filename, error):
  87. return
  88. encountered_error = error
  89. yield from log_error_records(f'{config_filename}: Error pinging monitor', error)
  90. if not encountered_error:
  91. repo_queue = Queue()
  92. for repo in location['repositories']:
  93. repo_queue.put((repo, 0),)
  94. while not repo_queue.empty():
  95. repository, retry_num = repo_queue.get()
  96. if isinstance(repository, str):
  97. repository = {'path': repository}
  98. timeout = retry_num * retry_wait
  99. if timeout:
  100. logger.warning(f'{config_filename}: Sleeping {timeout}s before next retry')
  101. time.sleep(timeout)
  102. try:
  103. yield from run_actions(
  104. arguments=arguments,
  105. config_filename=config_filename,
  106. location=location,
  107. storage=storage,
  108. retention=retention,
  109. consistency=consistency,
  110. hooks=hooks,
  111. local_path=local_path,
  112. remote_path=remote_path,
  113. local_borg_version=local_borg_version,
  114. repository=repository,
  115. )
  116. except (OSError, CalledProcessError, ValueError) as error:
  117. if retry_num < retries:
  118. repo_queue.put((repository, retry_num + 1),)
  119. tuple( # Consume the generator so as to trigger logging.
  120. log_error_records(
  121. f'{repository["path"]}: Error running actions for repository',
  122. error,
  123. levelno=logging.WARNING,
  124. log_command_error_output=True,
  125. )
  126. )
  127. logger.warning(
  128. f'{config_filename}: Retrying... attempt {retry_num + 1}/{retries}'
  129. )
  130. continue
  131. if command.considered_soft_failure(config_filename, error):
  132. return
  133. yield from log_error_records(
  134. f'{repository["path"]}: Error running actions for repository', error
  135. )
  136. encountered_error = error
  137. error_repository = repository['path']
  138. try:
  139. if using_primary_action:
  140. # send logs irrespective of error
  141. dispatch.call_hooks(
  142. 'ping_monitor',
  143. hooks,
  144. config_filename,
  145. monitor.MONITOR_HOOK_NAMES,
  146. monitor.State.LOG,
  147. monitoring_log_level,
  148. global_arguments.dry_run,
  149. )
  150. except (OSError, CalledProcessError) as error:
  151. if command.considered_soft_failure(config_filename, error):
  152. return
  153. encountered_error = error
  154. yield from log_error_records(f'{repository_path}: Error pinging monitor', error)
  155. if not encountered_error:
  156. try:
  157. if using_primary_action:
  158. dispatch.call_hooks(
  159. 'ping_monitor',
  160. hooks,
  161. config_filename,
  162. monitor.MONITOR_HOOK_NAMES,
  163. monitor.State.FINISH,
  164. monitoring_log_level,
  165. global_arguments.dry_run,
  166. )
  167. dispatch.call_hooks(
  168. 'destroy_monitor',
  169. hooks,
  170. config_filename,
  171. monitor.MONITOR_HOOK_NAMES,
  172. monitoring_log_level,
  173. global_arguments.dry_run,
  174. )
  175. except (OSError, CalledProcessError) as error:
  176. if command.considered_soft_failure(config_filename, error):
  177. return
  178. encountered_error = error
  179. yield from log_error_records(f'{config_filename}: Error pinging monitor', error)
  180. if encountered_error and using_primary_action:
  181. try:
  182. command.execute_hook(
  183. hooks.get('on_error'),
  184. hooks.get('umask'),
  185. config_filename,
  186. 'on-error',
  187. global_arguments.dry_run,
  188. repository=error_repository,
  189. error=encountered_error,
  190. output=getattr(encountered_error, 'output', ''),
  191. )
  192. dispatch.call_hooks(
  193. 'ping_monitor',
  194. hooks,
  195. config_filename,
  196. monitor.MONITOR_HOOK_NAMES,
  197. monitor.State.FAIL,
  198. monitoring_log_level,
  199. global_arguments.dry_run,
  200. )
  201. dispatch.call_hooks(
  202. 'destroy_monitor',
  203. hooks,
  204. config_filename,
  205. monitor.MONITOR_HOOK_NAMES,
  206. monitoring_log_level,
  207. global_arguments.dry_run,
  208. )
  209. except (OSError, CalledProcessError) as error:
  210. if command.considered_soft_failure(config_filename, error):
  211. return
  212. yield from log_error_records(f'{config_filename}: Error running on-error hook', error)
  213. def run_actions(
  214. *,
  215. arguments,
  216. config_filename,
  217. location,
  218. storage,
  219. retention,
  220. consistency,
  221. hooks,
  222. local_path,
  223. remote_path,
  224. local_borg_version,
  225. repository,
  226. ):
  227. '''
  228. Given parsed command-line arguments as an argparse.ArgumentParser instance, the configuration
  229. filename, several different configuration dicts, local and remote paths to Borg, a local Borg
  230. version string, and a repository name, run all actions from the command-line arguments on the
  231. given repository.
  232. Yield JSON output strings from executing any actions that produce JSON.
  233. Raise OSError or subprocess.CalledProcessError if an error occurs running a command for an
  234. action or a hook. Raise ValueError if the arguments or configuration passed to action are
  235. invalid.
  236. '''
  237. add_custom_log_levels()
  238. if isinstance(repository, str):
  239. repository = {'path': repository}
  240. repository_path = os.path.expanduser(repository['path'])
  241. global_arguments = arguments['global']
  242. dry_run_label = ' (dry run; not making any changes)' if global_arguments.dry_run else ''
  243. hook_context = {
  244. 'repository': repository_path,
  245. # Deprecated: For backwards compatibility with borgmatic < 1.6.0.
  246. 'repositories': ','.join([repo['path'] for repo in location['repositories']]),
  247. }
  248. command.execute_hook(
  249. hooks.get('before_actions'),
  250. hooks.get('umask'),
  251. config_filename,
  252. 'pre-actions',
  253. global_arguments.dry_run,
  254. **hook_context,
  255. )
  256. for (action_name, action_arguments) in arguments.items():
  257. if action_name == 'rcreate':
  258. borgmatic.actions.rcreate.run_rcreate(
  259. repository,
  260. storage,
  261. local_borg_version,
  262. action_arguments,
  263. global_arguments,
  264. local_path,
  265. remote_path,
  266. )
  267. elif action_name == 'transfer':
  268. borgmatic.actions.transfer.run_transfer(
  269. repository,
  270. storage,
  271. local_borg_version,
  272. action_arguments,
  273. global_arguments,
  274. local_path,
  275. remote_path,
  276. )
  277. elif action_name == 'create':
  278. yield from borgmatic.actions.create.run_create(
  279. config_filename,
  280. repository,
  281. location,
  282. storage,
  283. hooks,
  284. hook_context,
  285. local_borg_version,
  286. action_arguments,
  287. global_arguments,
  288. dry_run_label,
  289. local_path,
  290. remote_path,
  291. )
  292. elif action_name == 'prune':
  293. borgmatic.actions.prune.run_prune(
  294. config_filename,
  295. repository,
  296. storage,
  297. retention,
  298. hooks,
  299. hook_context,
  300. local_borg_version,
  301. action_arguments,
  302. global_arguments,
  303. dry_run_label,
  304. local_path,
  305. remote_path,
  306. )
  307. elif action_name == 'compact':
  308. borgmatic.actions.compact.run_compact(
  309. config_filename,
  310. repository,
  311. storage,
  312. retention,
  313. hooks,
  314. hook_context,
  315. local_borg_version,
  316. action_arguments,
  317. global_arguments,
  318. dry_run_label,
  319. local_path,
  320. remote_path,
  321. )
  322. elif action_name == 'check':
  323. if checks.repository_enabled_for_checks(repository, consistency):
  324. borgmatic.actions.check.run_check(
  325. config_filename,
  326. repository,
  327. location,
  328. storage,
  329. consistency,
  330. hooks,
  331. hook_context,
  332. local_borg_version,
  333. action_arguments,
  334. global_arguments,
  335. local_path,
  336. remote_path,
  337. )
  338. elif action_name == 'extract':
  339. borgmatic.actions.extract.run_extract(
  340. config_filename,
  341. repository,
  342. location,
  343. storage,
  344. hooks,
  345. hook_context,
  346. local_borg_version,
  347. action_arguments,
  348. global_arguments,
  349. local_path,
  350. remote_path,
  351. )
  352. elif action_name == 'export-tar':
  353. borgmatic.actions.export_tar.run_export_tar(
  354. repository,
  355. storage,
  356. local_borg_version,
  357. action_arguments,
  358. global_arguments,
  359. local_path,
  360. remote_path,
  361. )
  362. elif action_name == 'mount':
  363. borgmatic.actions.mount.run_mount(
  364. repository,
  365. storage,
  366. local_borg_version,
  367. arguments['mount'],
  368. local_path,
  369. remote_path,
  370. )
  371. elif action_name == 'restore':
  372. borgmatic.actions.restore.run_restore(
  373. repository,
  374. location,
  375. storage,
  376. hooks,
  377. local_borg_version,
  378. action_arguments,
  379. global_arguments,
  380. local_path,
  381. remote_path,
  382. )
  383. elif action_name == 'rlist':
  384. yield from borgmatic.actions.rlist.run_rlist(
  385. repository, storage, local_borg_version, action_arguments, local_path, remote_path,
  386. )
  387. elif action_name == 'list':
  388. yield from borgmatic.actions.list.run_list(
  389. repository, storage, local_borg_version, action_arguments, local_path, remote_path,
  390. )
  391. elif action_name == 'rinfo':
  392. yield from borgmatic.actions.rinfo.run_rinfo(
  393. repository, storage, local_borg_version, action_arguments, local_path, remote_path,
  394. )
  395. elif action_name == 'info':
  396. yield from borgmatic.actions.info.run_info(
  397. repository, storage, local_borg_version, action_arguments, local_path, remote_path,
  398. )
  399. elif action_name == 'break-lock':
  400. borgmatic.actions.break_lock.run_break_lock(
  401. repository,
  402. storage,
  403. local_borg_version,
  404. arguments['break-lock'],
  405. local_path,
  406. remote_path,
  407. )
  408. elif action_name == 'borg':
  409. borgmatic.actions.borg.run_borg(
  410. repository, storage, local_borg_version, action_arguments, local_path, remote_path,
  411. )
  412. command.execute_hook(
  413. hooks.get('after_actions'),
  414. hooks.get('umask'),
  415. config_filename,
  416. 'post-actions',
  417. global_arguments.dry_run,
  418. **hook_context,
  419. )
  420. def load_configurations(config_filenames, overrides=None, resolve_env=True):
  421. '''
  422. Given a sequence of configuration filenames, load and validate each configuration file. Return
  423. the results as a tuple of: dict of configuration filename to corresponding parsed configuration,
  424. and sequence of logging.LogRecord instances containing any parse errors.
  425. '''
  426. # Dict mapping from config filename to corresponding parsed config dict.
  427. configs = collections.OrderedDict()
  428. logs = []
  429. # Parse and load each configuration file.
  430. for config_filename in config_filenames:
  431. try:
  432. configs[config_filename], parse_logs = validate.parse_configuration(
  433. config_filename, validate.schema_filename(), overrides, resolve_env
  434. )
  435. logs.extend(parse_logs)
  436. except PermissionError:
  437. logs.extend(
  438. [
  439. logging.makeLogRecord(
  440. dict(
  441. levelno=logging.WARNING,
  442. levelname='WARNING',
  443. msg=f'{config_filename}: Insufficient permissions to read configuration file',
  444. )
  445. ),
  446. ]
  447. )
  448. except (ValueError, OSError, validate.Validation_error) as error:
  449. logs.extend(
  450. [
  451. logging.makeLogRecord(
  452. dict(
  453. levelno=logging.CRITICAL,
  454. levelname='CRITICAL',
  455. msg=f'{config_filename}: Error parsing configuration file',
  456. )
  457. ),
  458. logging.makeLogRecord(
  459. dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error)
  460. ),
  461. ]
  462. )
  463. return (configs, logs)
  464. def log_record(suppress_log=False, **kwargs):
  465. '''
  466. Create a log record based on the given makeLogRecord() arguments, one of which must be
  467. named "levelno". Log the record (unless suppress log is set) and return it.
  468. '''
  469. record = logging.makeLogRecord(kwargs)
  470. if suppress_log:
  471. return record
  472. logger.handle(record)
  473. return record
  474. def log_error_records(
  475. message, error=None, levelno=logging.CRITICAL, log_command_error_output=False
  476. ):
  477. '''
  478. Given error message text, an optional exception object, an optional log level, and whether to
  479. log the error output of a CalledProcessError (if any), log error summary information and also
  480. yield it as a series of logging.LogRecord instances.
  481. Note that because the logs are yielded as a generator, logs won't get logged unless you consume
  482. the generator output.
  483. '''
  484. level_name = logging._levelToName[levelno]
  485. if not error:
  486. yield log_record(levelno=levelno, levelname=level_name, msg=message)
  487. return
  488. try:
  489. raise error
  490. except CalledProcessError as error:
  491. yield log_record(levelno=levelno, levelname=level_name, msg=message)
  492. if error.output:
  493. # Suppress these logs for now and save full error output for the log summary at the end.
  494. yield log_record(
  495. levelno=levelno,
  496. levelname=level_name,
  497. msg=error.output,
  498. suppress_log=not log_command_error_output,
  499. )
  500. yield log_record(levelno=levelno, levelname=level_name, msg=error)
  501. except (ValueError, OSError) as error:
  502. yield log_record(levelno=levelno, levelname=level_name, msg=message)
  503. yield log_record(levelno=levelno, levelname=level_name, msg=error)
  504. except: # noqa: E722
  505. # Raising above only as a means of determining the error type. Swallow the exception here
  506. # because we don't want the exception to propagate out of this function.
  507. pass
  508. def get_local_path(configs):
  509. '''
  510. Arbitrarily return the local path from the first configuration dict. Default to "borg" if not
  511. set.
  512. '''
  513. return next(iter(configs.values())).get('location', {}).get('local_path', 'borg')
  514. def collect_configuration_run_summary_logs(configs, arguments):
  515. '''
  516. Given a dict of configuration filename to corresponding parsed configuration, and parsed
  517. command-line arguments as a dict from subparser name to a parsed namespace of arguments, run
  518. each configuration file and yield a series of logging.LogRecord instances containing summary
  519. information about each run.
  520. As a side effect of running through these configuration files, output their JSON results, if
  521. any, to stdout.
  522. '''
  523. # Run cross-file validation checks.
  524. repository = None
  525. for action_name, action_arguments in arguments.items():
  526. if hasattr(action_arguments, 'repository'):
  527. repository = getattr(action_arguments, 'repository')
  528. break
  529. try:
  530. if 'extract' in arguments or 'mount' in arguments:
  531. validate.guard_single_repository_selected(repository, configs)
  532. validate.guard_configuration_contains_repository(repository, configs)
  533. except ValueError as error:
  534. yield from log_error_records(str(error))
  535. return
  536. if not configs:
  537. yield from log_error_records(
  538. r"{' '.join(arguments['global'].config_paths)}: No valid configuration files found",
  539. )
  540. return
  541. if 'create' in arguments:
  542. try:
  543. for config_filename, config in configs.items():
  544. hooks = config.get('hooks', {})
  545. command.execute_hook(
  546. hooks.get('before_everything'),
  547. hooks.get('umask'),
  548. config_filename,
  549. 'pre-everything',
  550. arguments['global'].dry_run,
  551. )
  552. except (CalledProcessError, ValueError, OSError) as error:
  553. yield from log_error_records('Error running pre-everything hook', error)
  554. return
  555. # Execute the actions corresponding to each configuration file.
  556. json_results = []
  557. for config_filename, config in configs.items():
  558. results = list(run_configuration(config_filename, config, arguments))
  559. error_logs = tuple(result for result in results if isinstance(result, logging.LogRecord))
  560. if error_logs:
  561. yield from log_error_records(f'{config_filename}: An error occurred')
  562. yield from error_logs
  563. else:
  564. yield logging.makeLogRecord(
  565. dict(
  566. levelno=logging.INFO,
  567. levelname='INFO',
  568. msg=f'{config_filename}: Successfully ran configuration file',
  569. )
  570. )
  571. if results:
  572. json_results.extend(results)
  573. if 'umount' in arguments:
  574. logger.info(f"Unmounting mount point {arguments['umount'].mount_point}")
  575. try:
  576. borg_umount.unmount_archive(
  577. mount_point=arguments['umount'].mount_point, local_path=get_local_path(configs),
  578. )
  579. except (CalledProcessError, OSError) as error:
  580. yield from log_error_records('Error unmounting mount point', error)
  581. if json_results:
  582. sys.stdout.write(json.dumps(json_results))
  583. if 'create' in arguments:
  584. try:
  585. for config_filename, config in configs.items():
  586. hooks = config.get('hooks', {})
  587. command.execute_hook(
  588. hooks.get('after_everything'),
  589. hooks.get('umask'),
  590. config_filename,
  591. 'post-everything',
  592. arguments['global'].dry_run,
  593. )
  594. except (CalledProcessError, ValueError, OSError) as error:
  595. yield from log_error_records('Error running post-everything hook', error)
  596. def exit_with_help_link(): # pragma: no cover
  597. '''
  598. Display a link to get help and exit with an error code.
  599. '''
  600. logger.critical('')
  601. logger.critical('Need some help? https://torsion.org/borgmatic/#issues')
  602. sys.exit(1)
  603. def main(): # pragma: no cover
  604. configure_signals()
  605. try:
  606. arguments = parse_arguments(*sys.argv[1:])
  607. except ValueError as error:
  608. configure_logging(logging.CRITICAL)
  609. logger.critical(error)
  610. exit_with_help_link()
  611. except SystemExit as error:
  612. if error.code == 0:
  613. raise error
  614. configure_logging(logging.CRITICAL)
  615. logger.critical(f"Error parsing arguments: {' '.join(sys.argv)}")
  616. exit_with_help_link()
  617. global_arguments = arguments['global']
  618. if global_arguments.version:
  619. print(pkg_resources.require('borgmatic')[0].version)
  620. sys.exit(0)
  621. if global_arguments.bash_completion:
  622. print(borgmatic.commands.completion.bash_completion())
  623. sys.exit(0)
  624. config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
  625. configs, parse_logs = load_configurations(
  626. config_filenames, global_arguments.overrides, global_arguments.resolve_env
  627. )
  628. any_json_flags = any(
  629. getattr(sub_arguments, 'json', False) for sub_arguments in arguments.values()
  630. )
  631. colorama.init(
  632. autoreset=True,
  633. strip=not should_do_markup(global_arguments.no_color or any_json_flags, configs),
  634. )
  635. try:
  636. configure_logging(
  637. verbosity_to_log_level(global_arguments.verbosity),
  638. verbosity_to_log_level(global_arguments.syslog_verbosity),
  639. verbosity_to_log_level(global_arguments.log_file_verbosity),
  640. verbosity_to_log_level(global_arguments.monitoring_verbosity),
  641. global_arguments.log_file,
  642. )
  643. except (FileNotFoundError, PermissionError) as error:
  644. configure_logging(logging.CRITICAL)
  645. logger.critical(f'Error configuring logging: {error}')
  646. exit_with_help_link()
  647. logger.debug('Ensuring legacy configuration is upgraded')
  648. convert.guard_configuration_upgraded(LEGACY_CONFIG_PATH, config_filenames)
  649. summary_logs = parse_logs + list(collect_configuration_run_summary_logs(configs, arguments))
  650. summary_logs_max_level = max(log.levelno for log in summary_logs)
  651. for message in ('', 'summary:'):
  652. log_record(
  653. levelno=summary_logs_max_level,
  654. levelname=logging.getLevelName(summary_logs_max_level),
  655. msg=message,
  656. )
  657. for log in summary_logs:
  658. logger.handle(log)
  659. if summary_logs_max_level >= logging.CRITICAL:
  660. exit_with_help_link()