Skip to content

Commit

Permalink
feat(logging)!: Move logging setup to setup_logging, disable bevy L…
Browse files Browse the repository at this point in the history
…ogPlugin, add logging to file system (#446)

Implement LogPlugin in bones based off Bevy's LogPlugin. 

Shouldn't be much of a change in behavior, just 1st step in adding
additional log functionality in bones, such as saving game log files to
disk.

One difference is that it no longer includes the `tracing_error` crate
layer, I will review how this is used in bevy and see if we want to add
this dependency. Want to make sure not going to degrade in error
reporting quality for errors originating in bevy. (Plus maybe there is
something can learn from this / use in bones). Context:
https://github.com/bevyengine/bevy/blob/3cf70ba4f9d62396240b186ff379d27a312d2aa2/crates/bevy_log/src/lib.rs#L205

Logging is behind a feature flag, enabled by default. May be removed if
user wants their own global subscriber configured.
  • Loading branch information
MaxCWhitehead authored Sep 10, 2024
1 parent 870b47d commit bf745aa
Show file tree
Hide file tree
Showing 9 changed files with 605 additions and 3 deletions.
82 changes: 82 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions demos/assets_minimal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ struct GameMeta {
}

fn main() {
// Setup logging
setup_logs!();

// First create bones game.
let mut game = Game::new();

Expand Down
3 changes: 3 additions & 0 deletions demos/features/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ struct TileMeta {
struct PersistedTextData(String);

fn main() {
// Setup logging
setup_logs!();

// Register persistent data's schema so that it can be loaded by the storage loader.
PersistedTextData::register_schema();

Expand Down
3 changes: 3 additions & 0 deletions demos/hello_world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use bones_bevy_renderer::BonesBevyRenderer;
use bones_framework::prelude::*;

fn main() {
// Setup logging
setup_logs!();

// First create bones game.
let mut game = Game::new();

Expand Down
3 changes: 3 additions & 0 deletions demos/scripting/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ struct GameMeta {
}

fn main() {
// Setup logging
setup_logs!();

let mut game = Game::new();
game.install_plugin(DefaultGamePlugin);
game.shared_resource_mut::<AssetServer>()
Expand Down
3 changes: 2 additions & 1 deletion framework_crates/bones_bevy_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use render::*;
mod ui;
use ui::*;
mod rumble;
use bevy::prelude::*;
use bevy::{log::LogPlugin, prelude::*};
use bones::GamepadsRumble;
use bones_framework::prelude as bones;
use rumble::*;
Expand Down Expand Up @@ -145,6 +145,7 @@ impl BonesBevyRenderer {
}),
..default()
})
.disable::<LogPlugin>()
.build();
if self.pixel_art {
plugins = plugins.set(ImagePlugin::default_nearest());
Expand Down
23 changes: 21 additions & 2 deletions framework_crates/bones_framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ categories.workspace = true
keywords.workspace = true

[features]
default = ["image_png", "ui", "localization", "audio", "audio_ogg", "scripting"]
default = ["image_png", "ui", "localization", "logging", "audio", "audio_ogg", "scripting"]
#! Cargo feature supported in `bones_framework`.

## Enable the `ui` module, powered by [`egui`].
ui = ["dep:egui", "dep:ttf-parser"]
## Enable the localization module, powered by [`fluent`](https://github.com/projectfluent/fluent-rs).
localization = ["dep:fluent", "dep:fluent-langneg", "dep:intl-memoizer", "dep:unic-langid", "dep:sys-locale"]

logging = ["dep:tracing-subscriber", "dep:tracing-wasm", "dep:tracing-appender"]

## Enable the audio system.
audio = ["dep:kira"]

Expand Down Expand Up @@ -71,6 +73,12 @@ image_bmp = ["image/bmp"]
## Simulate dramatic network latency by inserting random sleeps into the networking code. This is extremely cheap and hacky but may be useful.
debug-network-slowdown = []

# Enables tracy tracing subscriber to capture tracing spans for profiling with Tracy.
#
# Note that bones is primarily instrumented with puffin scopes, tracy only captures tracing spans.
# This flag only enables span capture in logging plugin, `bevy/trace_tracy` may be used to enable tracy.
tracing-tracy = ["logging", "dep:tracing-tracy"]

document-features = ["dep:document-features"]

[dependencies]
Expand All @@ -92,7 +100,12 @@ instant = { version = "0.1", features = ["wasm-bindgen"] }
noise = "0.9"
once_cell = "1.17"
thiserror = "1.0"
tracing = "0.1"

# Tracing
tracing = "0.1"
tracing-subscriber = { version = "0.3", optional = true, features = ["env-filter"] }
tracing-appender = { version = "0.2", optional = true, features = ["parking_lot"] }
tracing-tracy = { version = "0.11.0", optional = true, default-features = false }

# Render
csscolorparser = "0.6"
Expand Down Expand Up @@ -139,3 +152,9 @@ smallvec = "1.10"
iroh-quinn = { version = "0.10" }
iroh-net = { version = "0.22" }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }


directories = "5.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
tracing-wasm = { version = "0.2.1", optional = true }
6 changes: 6 additions & 0 deletions framework_crates/bones_framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub mod prelude {

#[cfg(feature = "localization")]
pub use crate::localization::*;

#[cfg(feature = "logging")]
pub use crate::logging::prelude::*;
}

pub mod animation;
Expand All @@ -67,6 +70,9 @@ pub use bones_scripting as scripting;
#[cfg(feature = "localization")]
pub mod localization;

#[cfg(feature = "logging")]
pub mod logging;

/// External crate documentation.
///
/// This module only exists during docs builds and serves to make it eaiser to link to relevant
Expand Down
Loading

0 comments on commit bf745aa

Please sign in to comment.