-
Notifications
You must be signed in to change notification settings - Fork 38
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
Question: Logging target #344
Comments
@tarcieri : I can create a PR, but you may want to review before that... //! Abscissa tracing file-appender component
// cargo.toml: tracing-appender = "*"
use std::path::PathBuf;
use tracing_log::LogTracer;
use tracing_subscriber::{
layer::Layered,
fmt::{ //Formatter,
Layer,
format::{
DefaultFields,
Format, Full,
},
time::SystemTime,
},
Registry,
reload::Handle, EnvFilter,
};
pub use tracing_appender::{
rolling::{
RollingFileAppender,
Rotation,
},
non_blocking::{ NonBlocking, WorkerGuard},
};
use super::config::Config;
use crate::{Component, FrameworkError, FrameworkErrorKind};
/// Abscissa component for initializing the `tracing` subsystem
#[derive(Component, Debug)]
#[component(core)]
pub struct TracingAppender {
// filter_handle: Handle<EnvFilter, Formatter>,
filter_handle: Handle<EnvFilter, Layered<Layer<Registry, DefaultFields, Format<Full, SystemTime>, NonBlocking>, Registry, Registry>>,
worker_guard: WorkerGuard,
}
// Handle<EnvFilter, Layered<Layer<Registry, DefaultFields, Format<Full, SystemTime>, NonBlocking>, Registry, Registry>>
//layer::Layered<fmt_layer::Layer<Registry, N, E, W>, Registry>;
impl TracingAppender {
/// Create a new [`Tracing`] component from the given [`Config`].
pub fn new(config: Config, roll: Rotation, path: &PathBuf, file_name: &PathBuf) -> Result<Self, FrameworkError> {
let file_appender =
RollingFileAppender::new(roll, path, file_name);
let (non_blocking_appender, worker_guard) =
tracing_appender::non_blocking(file_appender);
// Configure log/tracing interoperability by setting a `LogTracer` as
// the global logger for the log crate, which converts all log events
// into tracing events.
LogTracer::init().map_err(|e| FrameworkErrorKind::ComponentError.context(e))?;
// Construct a tracing subscriber with the supplied filter and enable reloading.
let builder = tracing_subscriber::fmt()
.with_writer(non_blocking_appender)
.with_env_filter(config.filter)
.with_filter_reloading();
let filter_handle = builder.reload_handle();
let subscriber = builder.finish();
// Now set it as the global tracing subscriber and save the handle.
tracing::subscriber::set_global_default(subscriber)
.map_err(|e| FrameworkErrorKind::ComponentError.context(e))?;
info!("Initialized {:?} {:?}", path, file_name);
Ok(Self { filter_handle, worker_guard })
}
/// Return the currently-active tracing filter.
pub fn filter(&self) -> String {
self.filter_handle
.with_current(|filter| filter.to_string())
.expect("the subscriber is not dropped before the component is")
}
/// Reload the currently-active filter with the supplied value.
///
/// This can be used to provide a dynamic tracing filter endpoint.
pub fn reload_filter(&mut self, filter: impl Into<EnvFilter>) {
self.filter_handle
.reload(filter)
.expect("the subscriber is not dropped before the component is");
}
} |
I think it'd probably be better for you to maintain this as part of your own application or publish as a separate crate, unless there are framework changes strictly necessary to make it work. If there are, we can discuss what changes are necessary. The "preferred" way to solve this issue with Abscissa is using existing system level init and logging infrastructure. In the case of |
Most of my clients are on a Windows platform so I have to use a local log. I tried to have implement it only in my crate, but It is working though.. |
If there are specific changes to Abscissa you'd like for your logging needs, let us know. |
@tony-iqlusion 👍 Thanks for getting back to me... |
As a followup to "Damonizing and encrypting with Abscissa"..
Since I will be running as a daemon, I need to change some logging options:
Is there a way to do that? I've been digging but don't see a way short of modifying "application" and "trace/component"...
Thanks
JR
The text was updated successfully, but these errors were encountered: