Skip to content

Commit 6c184c3

Browse files
authored
add start_console_logging(bool) which accepts a flag. (#2102)
1 parent 16e340b commit 6c184c3

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ You can find its changes [documented below](#070---2021-01-01).
7878
- `Event::WindowScale` to notify widgets of the window's scale changes. ([#2335] by [@xStrom])
7979
- `Ctx::scale` method to all contexts for widgets to easily access the window's scale. ([#2335] by [@xStrom])
8080
- Add a public constructor to `StringCursor` ([#2319] by [@benoitryder])
81+
- App: add start_console_logging(bool) which accepts a flag. ([#2102] by [@ratmice])
8182

8283
### Changed
8384

@@ -580,6 +581,7 @@ Last release without a changelog :(
580581
[@benoitryder]: https://github.com/benoitryder
581582
[@sprocklem]: https://github.com/sprocklem
582583
[@cbondurant]: https://github.com/cbondurant
584+
[@ratmice]: https://github.com/ratmice
583585

584586
[#599]: https://github.com/linebender/druid/pull/599
585587
[#611]: https://github.com/linebender/druid/pull/611
@@ -863,6 +865,7 @@ Last release without a changelog :(
863865
[#2036]: https://github.com/linebender/druid/pull/2036
864866
[#2064]: https://github.com/linebender/druid/pull/2064
865867
[#1979]: https://github.com/linebender/druid/pull/1979
868+
[#2102]: https://github.com/linebender/druid/pull/2102
866869
[#2119]: https://github.com/linebender/druid/pull/2119
867870
[#2111]: https://github.com/linebender/druid/pull/2111
868871
[#2117]: https://github.com/linebender/druid/pull/2117

druid/src/app.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,17 @@ impl<T: Data> AppLauncher<T> {
190190
///
191191
/// # Panics
192192
///
193-
/// Panics if the subscriber fails to initialize, for example if a `tracing`/`tracing_wasm`
194-
/// global logger was already set.
195-
pub fn log_to_console(self) -> Self {
193+
/// Panics if `enable` is `true` and the subscriber fails to initialize,
194+
/// for example if a `tracing`/`tracing_wasm` global logger was already set.
195+
///
196+
/// Never panics when `enable` is `false`, or have any other side effect.
197+
///
198+
/// Passing in false is useful if you want to enable a global logger as feature
199+
/// but log to console otherwise.
200+
pub fn start_console_logging(self, enable: bool) -> Self {
201+
if !enable {
202+
return self;
203+
}
196204
#[cfg(not(target_arch = "wasm32"))]
197205
{
198206
use tracing_subscriber::prelude::*;
@@ -219,6 +227,10 @@ impl<T: Data> AppLauncher<T> {
219227
self
220228
}
221229

230+
/// Calls `start_console_logging` with `true`.
231+
pub fn log_to_console(self) -> Self {
232+
self.start_console_logging(true)
233+
}
222234
/// Use custom localization resource
223235
///
224236
/// `resources` is a list of file names that contain strings. `base_dir`

0 commit comments

Comments
 (0)