David Brown | e2acfae | 2020-01-21 16:45:01 -0700 | [diff] [blame] | 1 | // Copyright (c) 2017 Linaro LTD |
| 2 | // Copyright (c) 2019 JUUL Labs |
| 3 | // |
| 4 | // SPDX-License-Identifier: Apache-2.0 |
| 5 | |
David Brown | ca7b5d3 | 2017-11-03 08:37:38 -0600 | [diff] [blame] | 6 | //! Logging support for the test framework. |
| 7 | //! |
| 8 | //! https://stackoverflow.com/questions/30177845/how-to-initialize-the-logger-for-integration-tests |
| 9 | //! |
| 10 | //! The test framework runs the tests, possibly simultaneously, and in various orders. This helper |
| 11 | //! function, which should be called at the beginning of each test, will setup logging for all of |
| 12 | //! the tests. |
| 13 | |
Fabio Utzig | ffc673e | 2019-10-30 09:22:04 -0300 | [diff] [blame] | 14 | use std::sync::Once; |
David Brown | ca7b5d3 | 2017-11-03 08:37:38 -0600 | [diff] [blame] | 15 | |
Fabio Utzig | ffc673e | 2019-10-30 09:22:04 -0300 | [diff] [blame] | 16 | static INIT: Once = Once::new(); |
David Brown | ca7b5d3 | 2017-11-03 08:37:38 -0600 | [diff] [blame] | 17 | |
| 18 | /// Setup the logging system. Intended to be called at the beginning of each test. |
| 19 | pub fn setup() { |
| 20 | INIT.call_once(|| { |
Fabio Utzig | 25d7b0f | 2019-01-10 11:01:04 -0200 | [diff] [blame] | 21 | env_logger::init(); |
David Brown | ca7b5d3 | 2017-11-03 08:37:38 -0600 | [diff] [blame] | 22 | }); |
| 23 | } |