|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +# Copyright 2020 Google LLC |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | + |
| 18 | +from google.cloud.aiplatform import base |
| 19 | +import logging |
| 20 | + |
| 21 | + |
| 22 | +class TestLogging: |
| 23 | + def test_no_root_logging_handler_override(self, caplog): |
| 24 | + # Users should be able to control the root logger in their apps |
| 25 | + # The aiplatform module import should not override their root logger config |
| 26 | + caplog.set_level(logging.DEBUG) |
| 27 | + |
| 28 | + logging.debug("Debug level") |
| 29 | + logging.info("Info level") |
| 30 | + logging.critical("Critical level") |
| 31 | + |
| 32 | + assert "Debug level\n" in caplog.text |
| 33 | + assert "Info level\n" in caplog.text |
| 34 | + assert "Critical level\n" in caplog.text |
| 35 | + |
| 36 | + def test_log_level_coexistance(self, caplog): |
| 37 | + # The aiplatform module and the root logger can have different log levels. |
| 38 | + aip_logger = base.Logger(__name__) |
| 39 | + |
| 40 | + caplog.set_level(logging.DEBUG) |
| 41 | + |
| 42 | + logging.debug("This should exist") |
| 43 | + logging.info("This should too") |
| 44 | + |
| 45 | + aip_logger.info("This should also exist") |
| 46 | + aip_logger.debug("This should NOT exist") |
| 47 | + |
| 48 | + assert "This should exist\n" in caplog.text |
| 49 | + assert "This should too\n" in caplog.text |
| 50 | + assert "This should also exist\n" in caplog.text |
| 51 | + assert "This should NOT exist\n" not in caplog.text |
0 commit comments