Skip to content

Commit a09f8b9

Browse files
committed
add start_console_logging(bool) which accepts a flag.
1 parent 3790463 commit a09f8b9

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ You can find its changes [documented below](#070---2021-01-01).
6161
- `scroll_to_view` and `scroll_area_to_view` methods on `UpdateCtx`, `LifecycleCtx` and `EventCtx` ([#1976] by [@xarvic])
6262
- `Notification::route` ([#1978] by [@xarvic])
6363
- Build on OpenBSD ([#1993] by [@klemensn])
64-
- Scope: expose scoped state using state() and state_mut() ([#2082] by [@rjwittams]
65-
- Tabs: allow getting and setting the tab index of a Tabs widget ([#2082] by [@rjwittams]
64+
- Scope: expose scoped state using state() and state_mut() ([#2082] by [@rjwittams])
65+
- Tabs: allow getting and setting the tab index of a Tabs widget ([#2082] by [@rjwittams])
66+
- App: add start_console_logging(bool) which accepts a flag. ([#2102] by [@ratmice])
6667

6768
### Changed
6869

druid/src/app.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,17 @@ impl<T: Data> AppLauncher<T> {
185185
///
186186
/// # Panics
187187
///
188-
/// Panics if the subscriber fails to initialize, for example if a `tracing`/`tracing_wasm`
189-
/// global logger was already set.
190-
pub fn log_to_console(self) -> Self {
188+
/// Panics if `enable` is `true` and the subscriber fails to initialize,
189+
/// for example if a `tracing`/`tracing_wasm` global logger was already set.
190+
///
191+
/// Never panics when `enable` is `false`, or have any other side effect.
192+
///
193+
/// Passing in false is useful if you want to enable a global logger as feature
194+
/// but log to console otherwise.
195+
pub fn start_console_logging(self, enable: bool) -> Self {
196+
if !enable {
197+
return self;
198+
}
191199
#[cfg(not(target_arch = "wasm32"))]
192200
{
193201
use tracing_subscriber::prelude::*;
@@ -214,6 +222,10 @@ impl<T: Data> AppLauncher<T> {
214222
self
215223
}
216224

225+
/// Calls `start_console_logging` with `true`.
226+
pub fn log_to_console(self) -> Self {
227+
self.start_console_logging(true)
228+
}
217229
/// Use custom localization resource
218230
///
219231
/// `resources` is a list of file names that contain strings. `base_dir`

0 commit comments

Comments
 (0)