Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logging with interest cache #2165

Open
wants to merge 19 commits into
base: v0.1.x
Choose a base branch
from
14 changes: 6 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ env:
RUSTUP_MAX_RETRIES: 10
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
MSRV: 1.49.0
# TODO: remove this once tracing's MSRV is bumped.
APPENDER_MSRV: 1.53.0
MSRV: 1.61.0

jobs:
### check jobs ###
Expand Down Expand Up @@ -175,7 +173,7 @@ jobs:
shell: bash

check-msrv:
# Run `cargo check` on our minimum supported Rust version (1.49.0).
# Run `cargo check` on our minimum supported Rust version (1.61.0).
name: "cargo check (MSRV on ubuntu-latest)"
needs: check
runs-on: ubuntu-latest
Expand Down Expand Up @@ -219,16 +217,16 @@ jobs:

# TODO: remove this once tracing's MSRV is bumped.
check-msrv-appender:
# Run `cargo check` on our minimum supported Rust version (1.53.0).
# Run `cargo check` on our minimum supported Rust version (1.61.0).
name: "cargo check (tracing-appender MSRV)"
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "install Rust ${{ env.APPENDER_MSRV }}"
- name: "install Rust ${{ env.MSRV }}"
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.APPENDER_MSRV }}
toolchain: ${{ env.MSRV }}
profile: minimal
- name: "install Rust nightly"
uses: actions-rs/toolchain@v1
Expand All @@ -246,7 +244,7 @@ jobs:
with:
command: check
args: --all-features --locked -p tracing-appender
toolchain: ${{ env.APPENDER_MSRV }}
toolchain: ${{ env.MSRV }}

### test jobs #############################################################

Expand Down
2 changes: 1 addition & 1 deletion tracing-appender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ categories = [
]
keywords = ["logging", "tracing", "file-appender", "non-blocking-writer"]
edition = "2018"
rust-version = "1.53.0"
rust-version = "1.61.0"

[dependencies]
crossbeam-channel = "0.5.6"
Expand Down
2 changes: 1 addition & 1 deletion tracing-appender/src/rolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<'a> tracing_subscriber::fmt::writer::MakeWriter<'a> for RollingFileAppender
// Did we get the right to lock the file? If not, another thread
// did it and we can just make a writer.
if self.state.advance_date(now, current_time) {
self.state.refresh_writer(now, &mut *self.writer.write());
self.state.refresh_writer(now, &mut self.writer.write());
}
}
RollingWriter(self.writer.read())
Expand Down
2 changes: 1 addition & 1 deletion tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn gen_block<B: ToTokens>(
.into_iter()
.flat_map(|param| match param {
FnArg::Typed(PatType { pat, ty, .. }) => {
param_names(*pat, RecordType::parse_from_ty(&*ty))
param_names(*pat, RecordType::parse_from_ty(&ty))
}
FnArg::Receiver(_) => Box::new(iter::once((
Ident::new("self", param.span()),
Expand Down
2 changes: 1 addition & 1 deletion tracing-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ categories = [
]
keywords = ["logging", "tracing", "profiling"]
edition = "2018"
rust-version = "1.49.0"
rust-version = "1.61.0"

[features]
default = ["std", "valuable/std"]
Expand Down
38 changes: 24 additions & 14 deletions tracing-core/src/callsite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,21 @@
//! [`Dispatch`]: crate::dispatch::Dispatch
//! [macros]: https://docs.rs/tracing/latest/tracing/#macros
//! [instrument]: https://docs.rs/tracing/latest/tracing/attr.instrument.html
use crate::stdlib::{
any::TypeId,
fmt,
hash::{Hash, Hasher},
ptr,
sync::{
atomic::{AtomicBool, AtomicPtr, AtomicU8, Ordering},
Mutex,
use crate::{
dispatcher::Dispatch,
stdlib::{
any::TypeId,
fmt,
hash::{Hash, Hasher},
ptr,
sync::{
atomic::{AtomicBool, AtomicPtr, AtomicU8, Ordering},
Mutex,
},
vec::Vec,
},
vec::Vec,
};
use crate::{
dispatcher::Dispatch,
lazy::Lazy,
metadata::{LevelFilter, Metadata},
subscriber::Interest,
Expand Down Expand Up @@ -487,7 +489,9 @@ impl Callsites {

pub(crate) fn register_dispatch(dispatch: &Dispatch) {
let dispatchers = DISPATCHERS.register_dispatch(dispatch);
dispatch.subscriber().on_register_dispatch(dispatch);
if let Some(subscriber) = dispatch.subscriber() {
subscriber.on_register_dispatch(dispatch);
}
CALLSITES.rebuild_interest(dispatchers);
}

Expand Down Expand Up @@ -518,7 +522,10 @@ mod private {

#[cfg(feature = "std")]
mod dispatchers {
use crate::{dispatcher, lazy::Lazy};
use crate::{
dispatcher::{self, Dispatch},
lazy::Lazy,
};
use std::sync::{
atomic::{AtomicBool, Ordering},
RwLock, RwLockReadGuard, RwLockWriteGuard,
Expand Down Expand Up @@ -551,10 +558,13 @@ mod dispatchers {
Rebuilder::Read(LOCKED_DISPATCHERS.read().unwrap())
}

pub(super) fn register_dispatch(&self, dispatch: &dispatcher::Dispatch) -> Rebuilder<'_> {
pub(super) fn register_dispatch(&self, dispatch: &Dispatch) -> Rebuilder<'_> {
let mut dispatchers = LOCKED_DISPATCHERS.write().unwrap();
dispatchers.retain(|d| d.upgrade().is_some());
dispatchers.push(dispatch.registrar());

if let Some(registrar) = dispatch.registrar() {
dispatchers.push(registrar);
}
self.has_just_one
.store(dispatchers.len() <= 1, Ordering::SeqCst);
Rebuilder::Write(dispatchers)
Expand Down
Loading