Skip to content

Commit

Permalink
[terminal_async][core] Migrate tracing_logging from terminal_async to…
Browse files Browse the repository at this point in the history
… core
  • Loading branch information
nazmulidris committed Sep 26, 2024
1 parent 8dae43c commit bbc3145
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 61 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

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

16 changes: 15 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,21 @@ futures-util = "0.3.30" # Needed for cro
# Color gradients.
colorgrad = "0.7.0"

# Error handling.
thiserror = "1.0.63"
miette = { version = "7.2.0", features = ["fancy"] }
pretty_assertions = "1.4.0"

[dev-dependencies]
# for assert_eq! macro
pretty_assertions = "1.4.0"
serial_test = "3.1.1"
serial_test = "3.1.1"

# Testing - temp files and folders.
tempfile = "3.12.0"

# Bin targets for testing stdout and stderr.
assert_cmd = "2.0.16"
[[bin]]
name = "tracing_test_bin"
path = "src/bin/tracing_test_bin.rs"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

use r3bl_terminal_async::{init_tracing, DisplayPreference, TracingConfig, WriterConfig};
use r3bl_rs_utils_core::{init_tracing, DisplayPreference, TracingConfig, WriterConfig};

/// `assert_cmd` : <https://docs.rs/assert_cmd/latest/assert_cmd/index.html>
///
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub mod decl_macros;
pub mod logging;
pub mod misc;
pub mod terminal_io;
pub mod tracing_logging;
pub mod tui_core;

// Re-export.
Expand All @@ -140,4 +141,5 @@ pub use decl_macros::*;
pub use logging::*;
pub use misc::*;
pub use terminal_io::*;
pub use tracing_logging::*;
pub use tui_core::*;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
* limitations under the License.
*/

//! # [init_tracing]
//!
//! This is a convenience method to setup Tokio [`tracing_subscriber`] with `stdout` as
//! the output destination. This method also ensures that the [`crate::SharedWriter`] is
//! used for concurrent writes to `stdout`. You can also use the [`TracingConfig`] struct
//! to customize the behavior of the tracing setup, by choosing whether to display output
//! to `stdout`, `stderr`, or a [`crate::SharedWriter`]. By default, both display and file
//! logging are enabled. You can also customize the log level, and the file path and
//! prefix for the log file.
use tracing_core::LevelFilter;
use tracing_subscriber::{layer::SubscriberExt,
registry::LookupSpan,
Expand Down Expand Up @@ -258,9 +268,8 @@ mod test_tracing_bin_stdio {

#[cfg(test)]
mod test_tracing_shared_writer_output {
use r3bl_rs_utils_core::{LineStateControlSignal, SharedWriter};

use super::*;
use crate::{LineStateControlSignal, SharedWriter};

const EXPECTED: [&str; 4] = ["error", "warn", "info", "debug"];

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

use std::fmt::Debug;

use r3bl_rs_utils_core::SharedWriter;
use tracing_core::LevelFilter;

use crate::SharedWriter;

/// Configure the tracing logging to suit your needs. You can display the logs to a:
/// 1. file,
/// 2. stdout, stderr, or a shared writer,
Expand Down
9 changes: 0 additions & 9 deletions terminal_async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ async-stream = "0.3.5"
# Testing - r3bl-open-core.
r3bl_test_fixtures = { path = "../test_fixtures" }

# Testing - temp files and folders.
tempfile = "3.12.0"

# Bin targets for testing stdout and stderr.
assert_cmd = "2.0.16"
[[bin]]
name = "tracing_test_bin"
path = "src/bin/tracing_test_bin.rs"

[features]
default = ["emacs"]
emacs = []
12 changes: 0 additions & 12 deletions terminal_async/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ niceties & ergonomics that all Rustaceans 🦀 can enjoy 🎉.
- [Readline overview please see the docs for this struct for
details](#readline-overview-please-see-the-docs-for-this-struct-for-details)
- [Spinner::try_start](#spinnertry_start)
- [init_tracing()](#init_tracing)
- [Build this crate with Naz on YouTube](#build-this-crate-with-naz-on-youtube)
- [Why another async readline crate?](#why-another-async-readline-crate)
- [References for blocking and thread cancellation in
Expand Down Expand Up @@ -365,17 +364,6 @@ have ANSI escape sequences in them. Here's an example of this.
Ok(())
```

### [`init_tracing()`]

This is a convenience method to setup Tokio [`tracing_subscriber`] with `stdout` as
the output destination. This method also ensures that the
[`r3bl_rs_utils_core::SharedWriter`] is used for concurrent writes to `stdout`. You
can also use the [`TracingConfig`] struct to customize the behavior of the tracing
setup, by choosing whether to display output to `stdout`, `stderr`, or a
[`r3bl_rs_utils_core::SharedWriter`]. By default, both display and file logging are
enabled. You can also customize the log level, and the file path and prefix for the
log file.

## Build this crate with Naz on YouTube

Watch the following videos to learn more about how this crate was built:
Expand Down
10 changes: 5 additions & 5 deletions terminal_async/examples/terminal_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use std::{io::{stderr, Write},

use crossterm::style::Stylize;
use miette::IntoDiagnostic;
use r3bl_rs_utils_core::SharedWriter;
use r3bl_terminal_async::{tracing_logging::tracing_config::TracingConfig,
DisplayPreference,
Readline,
use r3bl_rs_utils_core::{tracing_logging::tracing_config::TracingConfig,
DisplayPreference,
SharedWriter};
use r3bl_terminal_async::{Readline,
ReadlineEvent,
Spinner,
SpinnerStyle,
Expand Down Expand Up @@ -152,7 +152,7 @@ async fn main() -> miette::Result<()> {
}

// Initialize tracing w/ the "async stdout" (SharedWriter), and file writer.
r3bl_terminal_async::init_tracing(TracingConfig::new_file_and_display(
r3bl_rs_utils_core::init_tracing(TracingConfig::new_file_and_display(
None,
DisplayPreference::SharedWriter(terminal_async.clone_shared_writer()),
))?;
Expand Down
14 changes: 0 additions & 14 deletions terminal_async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
//! - [Readline overview please see the docs for this struct for
//! details](#readline-overview-please-see-the-docs-for-this-struct-for-details)
//! - [Spinner::try_start](#spinnertry_start)
//! - [init_tracing()](#init_tracing)
//! - [Build this crate with Naz on YouTube](#build-this-crate-with-naz-on-youtube)
//! - [Why another async readline crate?](#why-another-async-readline-crate)
//! - [References for blocking and thread cancellation in
Expand Down Expand Up @@ -384,17 +383,6 @@
//! # }
//! ```
//!
//! ## [`init_tracing()`]
//!
//! This is a convenience method to setup Tokio [`tracing_subscriber`] with `stdout` as
//! the output destination. This method also ensures that the
//! [`r3bl_rs_utils_core::SharedWriter`] is used for concurrent writes to `stdout`. You
//! can also use the [`TracingConfig`] struct to customize the behavior of the tracing
//! setup, by choosing whether to display output to `stdout`, `stderr`, or a
//! [`r3bl_rs_utils_core::SharedWriter`]. By default, both display and file logging are
//! enabled. You can also customize the log level, and the file path and prefix for the
//! log file.
//!
//! # Build this crate with Naz on YouTube
//!
//! Watch the following videos to learn more about how this crate was built:
Expand Down Expand Up @@ -471,14 +459,12 @@ pub mod public_api;
pub mod readline_impl;
pub mod spinner_impl;
pub mod tracing_jaeger;
pub mod tracing_logging;

// Re-export the public API.
pub use public_api::*;
pub use readline_impl::*;
pub use spinner_impl::*;
pub use tracing_jaeger::*;
pub use tracing_logging::*;

// External crates.
use std::{collections::VecDeque, io::Error, pin::Pin, sync::Arc};
Expand Down
8 changes: 4 additions & 4 deletions tui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -877,15 +877,15 @@ let st = lolcat_mut.colorize_to_styled_texts(&unicode_string);
lolcat.next_color();
```

This [crate::Lolcat] that is returned by `build()` is safe to re-use.
This [r3bl_rs_utils_core::Lolcat] that is returned by `build()` is safe to re-use.
- The colors it cycles through are "stable" meaning that once constructed via the
[builder](crate::LolcatBuilder) (which sets the speed, seed, and delta that
determine where the color wheel starts when it is used). For eg, when used in a
[builder](r3bl_rs_utils_core::LolcatBuilder) (which sets the speed, seed, and delta
that determine where the color wheel starts when it is used). For eg, when used in a
dialog box component that re-uses the instance, repeated calls to the `render()`
function of this component will produce the same generated colors over and over
again.
- If you want to change where the color wheel "begins", you have to change the speed,
seed, and delta of this [crate::Lolcat] instance.
seed, and delta of this [r3bl_rs_utils_core::Lolcat] instance.

## Issues and PRs

Expand Down
8 changes: 4 additions & 4 deletions tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,15 +892,15 @@
//! lolcat.next_color();
//! ```
//!
//! This [crate::Lolcat] that is returned by `build()` is safe to re-use.
//! This [r3bl_rs_utils_core::Lolcat] that is returned by `build()` is safe to re-use.
//! - The colors it cycles through are "stable" meaning that once constructed via the
//! [builder](crate::LolcatBuilder) (which sets the speed, seed, and delta that
//! determine where the color wheel starts when it is used). For eg, when used in a
//! [builder](r3bl_rs_utils_core::LolcatBuilder) (which sets the speed, seed, and delta
//! that determine where the color wheel starts when it is used). For eg, when used in a
//! dialog box component that re-uses the instance, repeated calls to the `render()`
//! function of this component will produce the same generated colors over and over
//! again.
//! - If you want to change where the color wheel "begins", you have to change the speed,
//! seed, and delta of this [crate::Lolcat] instance.
//! seed, and delta of this [r3bl_rs_utils_core::Lolcat] instance.
//!
//! # Issues and PRs
//!
Expand Down
2 changes: 1 addition & 1 deletion tui/src/tui/layout/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use r3bl_rs_utils_core::{Position, RequestedSizePercent, Size, TuiStyle};

use super::{FlexBoxId, LayoutDirection};

/// Properties that are needed to create a [FlexBox].
/// Properties that are needed to create a [crate::FlexBox].
#[derive(Clone, Debug, Default)]
pub struct FlexBoxProps {
pub id: FlexBoxId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ use crate::{constants::{AUTHORS,
StyleUSSpanLines,
US};

/// This is the main function that the [editor] uses this in order to display the markdown to the
/// user.It is responsible for converting:
/// - from a &[Vec] of [US] which comes from the [editor],
/// - into a [StyleUSSpanLines], which the [editor] will clip & render.
/// This is the main function that the [crate::editor] uses this in order to display the
/// markdown to the user.It is responsible for converting:
/// - from a &[Vec] of [US] which comes from the [crate::editor],
/// - into a [StyleUSSpanLines], which the [crate::editor] will clip & render.
///
/// # Arguments
/// - `editor_text` - The text that the user has typed into the editor.
Expand Down
3 changes: 2 additions & 1 deletion tui/src/tui/terminal_lib_backends/z_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub enum ZOrder {
}

impl ZOrder {
/// Contains the priority that is used to paint the different groups of [RenderOp] items.
/// Contains the priority that is used to paint the different groups of
/// [crate::RenderOp] items.
pub fn get_render_order() -> [ZOrder; 3] {
[ZOrder::Normal, ZOrder::High, ZOrder::Glass]
}
Expand Down

0 comments on commit bbc3145

Please sign in to comment.