mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-06-27 00:56:36 +02:00
feat: Support logging to journald with tracing-journald
Some checks failed
Release Docker Image / define-variables (push) Failing after 1s
Release Docker Image / build-image (linux/amd64, linux-amd64) (push) Has been skipped
Release Docker Image / build-image (linux/arm64, linux-arm64) (push) Has been skipped
Release Docker Image / merge (push) Has been skipped
Rust Checks / Format (push) Failing after 2s
Rust Checks / Clippy (push) Failing after 8s
Rust Checks / Cargo Test (push) Failing after 9s
Some checks failed
Release Docker Image / define-variables (push) Failing after 1s
Release Docker Image / build-image (linux/amd64, linux-amd64) (push) Has been skipped
Release Docker Image / build-image (linux/arm64, linux-arm64) (push) Has been skipped
Release Docker Image / merge (push) Has been skipped
Rust Checks / Format (push) Failing after 2s
Rust Checks / Clippy (push) Failing after 8s
Rust Checks / Cargo Test (push) Failing after 9s
This stubs out on non-unix platforms.
This commit is contained in:
parent
843ffa0ab9
commit
9eb1d098bd
8 changed files with 91 additions and 2 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -794,6 +794,7 @@ dependencies = [
|
||||||
"tokio-metrics",
|
"tokio-metrics",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-flame",
|
"tracing-flame",
|
||||||
|
"tracing-journald",
|
||||||
"tracing-opentelemetry",
|
"tracing-opentelemetry",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
@ -5067,6 +5068,17 @@ dependencies = [
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tracing-journald"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fc0b4143302cf1022dac868d521e36e8b27691f72c84b3311750d5188ebba657"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"tracing-core",
|
||||||
|
"tracing-subscriber",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-log"
|
name = "tracing-log"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
|
|
@ -213,6 +213,8 @@ default-features = false
|
||||||
version = "0.3.19"
|
version = "0.3.19"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["env-filter", "std", "tracing", "tracing-log", "ansi", "fmt"]
|
features = ["env-filter", "std", "tracing", "tracing-log", "ansi", "fmt"]
|
||||||
|
[workspace.dependencies.tracing-journald]
|
||||||
|
version = "0.3.1"
|
||||||
[workspace.dependencies.tracing-core]
|
[workspace.dependencies.tracing-core]
|
||||||
version = "0.1.33"
|
version = "0.1.33"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
|
@ -16,6 +16,10 @@ DeviceAllow=char-tty
|
||||||
StandardInput=tty-force
|
StandardInput=tty-force
|
||||||
StandardOutput=tty
|
StandardOutput=tty
|
||||||
StandardError=journal+console
|
StandardError=journal+console
|
||||||
|
|
||||||
|
Environment="CONTINUWUITY_LOG_TO_JOURNALD=1"
|
||||||
|
Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N"
|
||||||
|
|
||||||
TTYReset=yes
|
TTYReset=yes
|
||||||
# uncomment to allow buffer to be cleared every restart
|
# uncomment to allow buffer to be cleared every restart
|
||||||
TTYVTDisallocate=no
|
TTYVTDisallocate=no
|
||||||
|
|
|
@ -660,6 +660,15 @@
|
||||||
#
|
#
|
||||||
#log_thread_ids = false
|
#log_thread_ids = false
|
||||||
|
|
||||||
|
# Enable journald logging on Unix platforms
|
||||||
|
#
|
||||||
|
#log_to_journald = false
|
||||||
|
|
||||||
|
# The syslog identifier to use with journald logging
|
||||||
|
# Only used when journald logging is enabled
|
||||||
|
#
|
||||||
|
#journald_identifier = "conduwuit"
|
||||||
|
|
||||||
# OpenID token expiration/TTL in seconds.
|
# OpenID token expiration/TTL in seconds.
|
||||||
#
|
#
|
||||||
# These are the OpenID tokens that are primarily used for Matrix account
|
# These are the OpenID tokens that are primarily used for Matrix account
|
||||||
|
|
3
debian/conduwuit.service
vendored
3
debian/conduwuit.service
vendored
|
@ -14,6 +14,9 @@ Type=notify
|
||||||
|
|
||||||
Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml"
|
Environment="CONTINUWUITY_CONFIG=/etc/conduwuit/conduwuit.toml"
|
||||||
|
|
||||||
|
Environment="CONTINUWUITY_LOG_TO_JOURNALD=1"
|
||||||
|
Environment="CONTINUWUITY_JOURNALD_IDENTIFIER=%N"
|
||||||
|
|
||||||
ExecStart=/usr/sbin/conduwuit
|
ExecStart=/usr/sbin/conduwuit
|
||||||
|
|
||||||
ReadWritePaths=/var/lib/conduwuit /etc/conduwuit
|
ReadWritePaths=/var/lib/conduwuit /etc/conduwuit
|
||||||
|
|
|
@ -795,6 +795,24 @@ pub struct Config {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub log_thread_ids: bool,
|
pub log_thread_ids: bool,
|
||||||
|
|
||||||
|
/// Enable journald logging on Unix platforms
|
||||||
|
///
|
||||||
|
/// When enabled, log output will be sent to the systemd journal
|
||||||
|
/// This is only supported on Unix platforms
|
||||||
|
///
|
||||||
|
/// default: false
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
#[serde(default)]
|
||||||
|
pub log_to_journald: bool,
|
||||||
|
|
||||||
|
/// The syslog identifier to use with journald logging
|
||||||
|
///
|
||||||
|
/// Only used when journald logging is enabled
|
||||||
|
///
|
||||||
|
/// Defaults to the binary name
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
pub journald_identifier: Option<String>,
|
||||||
|
|
||||||
/// OpenID token expiration/TTL in seconds.
|
/// OpenID token expiration/TTL in seconds.
|
||||||
///
|
///
|
||||||
/// These are the OpenID tokens that are primarily used for Matrix account
|
/// These are the OpenID tokens that are primarily used for Matrix account
|
||||||
|
|
|
@ -43,6 +43,7 @@ default = [
|
||||||
"io_uring",
|
"io_uring",
|
||||||
"jemalloc",
|
"jemalloc",
|
||||||
"jemalloc_conf",
|
"jemalloc_conf",
|
||||||
|
"journald",
|
||||||
"media_thumbnail",
|
"media_thumbnail",
|
||||||
"release_max_log_level",
|
"release_max_log_level",
|
||||||
"systemd",
|
"systemd",
|
||||||
|
@ -130,6 +131,11 @@ sentry_telemetry = [
|
||||||
systemd = [
|
systemd = [
|
||||||
"conduwuit-router/systemd",
|
"conduwuit-router/systemd",
|
||||||
]
|
]
|
||||||
|
journald = [ # This is a stub on non-unix platforms
|
||||||
|
"dep:tracing-journald",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# enable the tokio_console server ncompatible with release_max_log_level
|
# enable the tokio_console server ncompatible with release_max_log_level
|
||||||
tokio_console = [
|
tokio_console = [
|
||||||
"dep:console-subscriber",
|
"dep:console-subscriber",
|
||||||
|
@ -183,6 +189,7 @@ tracing-opentelemetry.optional = true
|
||||||
tracing-opentelemetry.workspace = true
|
tracing-opentelemetry.workspace = true
|
||||||
tracing-subscriber.workspace = true
|
tracing-subscriber.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
|
tracing-journald = { workspace = true, optional = true }
|
||||||
|
|
||||||
[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies]
|
[target.'cfg(all(not(target_env = "msvc"), target_os = "linux"))'.dependencies]
|
||||||
hardened_malloc-rs.workspace = true
|
hardened_malloc-rs.workspace = true
|
||||||
|
|
|
@ -43,6 +43,15 @@ pub(crate) fn init(
|
||||||
.with(console_layer.with_filter(console_reload_filter))
|
.with(console_layer.with_filter(console_reload_filter))
|
||||||
.with(cap_layer);
|
.with(cap_layer);
|
||||||
|
|
||||||
|
// If journald logging is enabled on Unix platforms, create a separate
|
||||||
|
// subscriber for it
|
||||||
|
#[cfg(all(target_family = "unix", feature = "journald"))]
|
||||||
|
if config.log_to_journald {
|
||||||
|
if let Err(e) = init_journald_logging(config) {
|
||||||
|
eprintln!("Failed to initialize journald logging: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "sentry_telemetry")]
|
#[cfg(feature = "sentry_telemetry")]
|
||||||
let subscriber = {
|
let subscriber = {
|
||||||
let sentry_filter = EnvFilter::try_new(&config.sentry_filter)
|
let sentry_filter = EnvFilter::try_new(&config.sentry_filter)
|
||||||
|
@ -122,6 +131,28 @@ pub(crate) fn init(
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(target_family = "unix", feature = "journald"))]
|
||||||
|
fn init_journald_logging(config: &Config) -> Result<()> {
|
||||||
|
use tracing_journald::Layer as JournaldLayer;
|
||||||
|
|
||||||
|
let journald_filter =
|
||||||
|
EnvFilter::try_new(&config.log).map_err(|e| err!(Config("log", "{e}.")))?;
|
||||||
|
|
||||||
|
let mut journald_layer = JournaldLayer::new()
|
||||||
|
.map_err(|e| err!(Config("journald", "Failed to initialize journald layer: {e}.")))?;
|
||||||
|
|
||||||
|
if let Some(ref identifier) = config.journald_identifier {
|
||||||
|
journald_layer = journald_layer.with_syslog_identifier(identifier.to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
|
let journald_subscriber =
|
||||||
|
Registry::default().with(journald_layer.with_filter(journald_filter));
|
||||||
|
|
||||||
|
let _guard = tracing::subscriber::set_default(journald_subscriber);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn tokio_console_enabled(config: &Config) -> (bool, &'static str) {
|
fn tokio_console_enabled(config: &Config) -> (bool, &'static str) {
|
||||||
if !cfg!(all(feature = "tokio_console", tokio_unstable)) {
|
if !cfg!(all(feature = "tokio_console", tokio_unstable)) {
|
||||||
return (false, "");
|
return (false, "");
|
||||||
|
@ -141,7 +172,10 @@ fn tokio_console_enabled(config: &Config) -> (bool, &'static str) {
|
||||||
(true, "")
|
(true, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_global_default<S: SubscriberExt + Send + Sync>(subscriber: S) {
|
fn set_global_default<S>(subscriber: S)
|
||||||
|
where
|
||||||
|
S: tracing::Subscriber + Send + Sync + 'static,
|
||||||
|
{
|
||||||
tracing::subscriber::set_global_default(subscriber)
|
tracing::subscriber::set_global_default(subscriber)
|
||||||
.expect("the global default tracing subscriber failed to be initialized");
|
.expect("the global default tracing subscriber failed to be initialized");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue