|
| 1 | +// Copyright 2020 Contributors to the Parsec project. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +use std::sync::atomic::AtomicBool; |
| 4 | +use std::sync::atomic::Ordering; |
| 5 | + |
| 6 | +/// Configuration values that affect most or all the |
| 7 | +/// components of the service. |
| 8 | +#[derive(Default, Debug)] |
| 9 | +pub struct GlobalConfig { |
| 10 | + log_error_details: AtomicBool, |
| 11 | +} |
| 12 | + |
| 13 | +impl GlobalConfig { |
| 14 | + const fn new() -> Self { |
| 15 | + GlobalConfig { |
| 16 | + log_error_details: AtomicBool::new(false), |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | + /// Determine whether error logs should include detailed |
| 21 | + /// information about the error |
| 22 | + pub fn log_error_details() -> bool { |
| 23 | + GLOBAL_CONFIG.log_error_details.load(Ordering::Relaxed) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +static GLOBAL_CONFIG: GlobalConfig = GlobalConfig::new(); |
| 28 | + |
| 29 | +pub(super) struct GlobalConfigBuilder { |
| 30 | + log_error_details: bool, |
| 31 | +} |
| 32 | + |
| 33 | +impl GlobalConfigBuilder { |
| 34 | + pub fn new() -> Self { |
| 35 | + GlobalConfigBuilder { |
| 36 | + log_error_details: false, |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + pub fn with_log_error_details(mut self, log_error_details: bool) -> Self { |
| 41 | + self.log_error_details = log_error_details; |
| 42 | + |
| 43 | + self |
| 44 | + } |
| 45 | + |
| 46 | + pub fn build(self) { |
| 47 | + GLOBAL_CONFIG |
| 48 | + .log_error_details |
| 49 | + .store(self.log_error_details, Ordering::Relaxed); |
| 50 | + } |
| 51 | +} |
0 commit comments