We should be able to configure additional log handlers.
(tmp_path, capsys)
| 806 | |
| 807 | |
| 808 | def test_logging_config(tmp_path, capsys): |
| 809 | """We should be able to configure additional log handlers.""" |
| 810 | log_file = tmp_path / "log_file" |
| 811 | app = Application( |
| 812 | logging_config={ |
| 813 | "version": 1, |
| 814 | "handlers": { |
| 815 | "file": { |
| 816 | "class": "logging.FileHandler", |
| 817 | "level": "DEBUG", |
| 818 | "filename": str(log_file), |
| 819 | }, |
| 820 | }, |
| 821 | "loggers": { |
| 822 | "Application": { |
| 823 | "level": "DEBUG", |
| 824 | "handlers": ["console", "file"], |
| 825 | }, |
| 826 | }, |
| 827 | } |
| 828 | ) |
| 829 | # the default "console" handler + our new "file" handler |
| 830 | assert len(app.log.handlers) == 2 |
| 831 | |
| 832 | # log a couple of messages |
| 833 | app.log.info("info") |
| 834 | app.log.warning("warn") |
| 835 | |
| 836 | # test that log messages get written to the file |
| 837 | with open(log_file) as log_handle: |
| 838 | assert log_handle.read() == "info\nwarn\n" |
| 839 | |
| 840 | # test that log messages get written to stderr (default console handler) |
| 841 | assert capsys.readouterr().err == "[Application] WARNING | warn\n" |
| 842 | |
| 843 | |
| 844 | def test_get_default_logging_config_pythonw(monkeypatch): |
nothing calls this directly
no test coverage detected
searching dependent graphs…