mirror of
https://github.com/telemt/telemt.git
synced 2026-05-22 19:51:43 +03:00
Fixes for SILENT-mode by #792
Signed-off-by: Alexey <247128645+axkurcom@users.noreply.github.com>
This commit is contained in:
@@ -21,8 +21,7 @@ pub enum LogLevel {
|
|||||||
#[default]
|
#[default]
|
||||||
Normal,
|
Normal,
|
||||||
/// Minimal output: only warnings and errors (warn + error).
|
/// Minimal output: only warnings and errors (warn + error).
|
||||||
/// Startup messages (config, DC connectivity, proxy links) are always shown
|
/// Proxy links may still be emitted through their dedicated target.
|
||||||
/// via info! before the filter is applied.
|
|
||||||
Silent,
|
Silent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ use crate::transport::middle_proxy::{
|
|||||||
save_proxy_config_cache,
|
save_proxy_config_cache,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MAESTRO_COLOR: &str = "\x1b[92m";
|
||||||
|
const COLOR_RESET: &str = "\x1b[0m";
|
||||||
|
|
||||||
|
pub(crate) fn print_maestro_line(message: impl AsRef<str>) {
|
||||||
|
eprintln!("{MAESTRO_COLOR}MAESTRO{COLOR_RESET}: {}", message.as_ref());
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn resolve_runtime_config_path(
|
pub(crate) fn resolve_runtime_config_path(
|
||||||
config_path_cli: &str,
|
config_path_cli: &str,
|
||||||
startup_cwd: &Path,
|
startup_cwd: &Path,
|
||||||
@@ -501,7 +508,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn print_proxy_links(host: &str, port: u16, config: &ProxyConfig) {
|
pub(crate) fn print_proxy_links(host: &str, port: u16, config: &ProxyConfig) {
|
||||||
info!(target: "telemt::links", "--- Proxy Links ({}) ---", host);
|
print_maestro_line(format!("Proxy links ({host})"));
|
||||||
for user_name in config
|
for user_name in config
|
||||||
.general
|
.general
|
||||||
.links
|
.links
|
||||||
@@ -509,20 +516,16 @@ pub(crate) fn print_proxy_links(host: &str, port: u16, config: &ProxyConfig) {
|
|||||||
.resolve_users(&config.access.users)
|
.resolve_users(&config.access.users)
|
||||||
{
|
{
|
||||||
if let Some(secret) = config.access.users.get(user_name) {
|
if let Some(secret) = config.access.users.get(user_name) {
|
||||||
info!(target: "telemt::links", "User: {}", user_name);
|
print_maestro_line(format!("User: {user_name}"));
|
||||||
if config.general.modes.classic {
|
if config.general.modes.classic {
|
||||||
info!(
|
print_maestro_line(format!(
|
||||||
target: "telemt::links",
|
"Classic: tg://proxy?server={host}&port={port}&secret={secret}"
|
||||||
" Classic: tg://proxy?server={}&port={}&secret={}",
|
));
|
||||||
host, port, secret
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if config.general.modes.secure {
|
if config.general.modes.secure {
|
||||||
info!(
|
print_maestro_line(format!(
|
||||||
target: "telemt::links",
|
"DD: tg://proxy?server={host}&port={port}&secret=dd{secret}"
|
||||||
" DD: tg://proxy?server={}&port={}&secret=dd{}",
|
));
|
||||||
host, port, secret
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if config.general.modes.tls {
|
if config.general.modes.tls {
|
||||||
let mut domains = Vec::with_capacity(1 + config.censorship.tls_domains.len());
|
let mut domains = Vec::with_capacity(1 + config.censorship.tls_domains.len());
|
||||||
@@ -535,18 +538,15 @@ pub(crate) fn print_proxy_links(host: &str, port: u16, config: &ProxyConfig) {
|
|||||||
|
|
||||||
for domain in domains {
|
for domain in domains {
|
||||||
let domain_hex = hex::encode(&domain);
|
let domain_hex = hex::encode(&domain);
|
||||||
info!(
|
print_maestro_line(format!(
|
||||||
target: "telemt::links",
|
"EE-TLS: tg://proxy?server={host}&port={port}&secret=ee{secret}{domain_hex}"
|
||||||
" EE-TLS: tg://proxy?server={}&port={}&secret=ee{}{}",
|
));
|
||||||
host, port, secret, domain_hex
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!(target: "telemt::links", "User '{}' in show_link not found", user_name);
|
warn!(target: "telemt::links", "User '{}' in show_link not found", user_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
info!(target: "telemt::links", "------------------------");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn write_beobachten_snapshot(path: &str, payload: &str) -> std::io::Result<()> {
|
pub(crate) async fn write_beobachten_snapshot(path: &str, payload: &str) -> std::io::Result<()> {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ use crate::stats::{ReplayChecker, Stats};
|
|||||||
use crate::stream::BufferPool;
|
use crate::stream::BufferPool;
|
||||||
use crate::transport::UpstreamManager;
|
use crate::transport::UpstreamManager;
|
||||||
use crate::transport::middle_proxy::MePool;
|
use crate::transport::middle_proxy::MePool;
|
||||||
use helpers::{parse_cli, resolve_runtime_base_dir, resolve_runtime_config_path};
|
use helpers::{parse_cli, print_maestro_line, resolve_runtime_base_dir, resolve_runtime_config_path};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use crate::daemon::{DaemonOptions, PidFile, drop_privileges};
|
use crate::daemon::{DaemonOptions, PidFile, drop_privileges};
|
||||||
@@ -325,7 +325,9 @@ async fn run_telemt_core(
|
|||||||
config.general.log_level.clone()
|
config.general.log_level.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (filter_layer, filter_handle) = reload::Layer::new(EnvFilter::new("info"));
|
let initial_filter_spec = runtime_tasks::log_filter_spec(has_rust_log, &effective_log_level);
|
||||||
|
let (filter_layer, filter_handle) =
|
||||||
|
reload::Layer::new(EnvFilter::new(initial_filter_spec.clone()));
|
||||||
startup_tracker
|
startup_tracker
|
||||||
.start_component(
|
.start_component(
|
||||||
COMPONENT_TRACING_INIT,
|
COMPONENT_TRACING_INIT,
|
||||||
@@ -356,7 +358,7 @@ async fn run_telemt_core(
|
|||||||
destination: log_destination,
|
destination: log_destination,
|
||||||
disable_colors: true,
|
disable_colors: true,
|
||||||
};
|
};
|
||||||
let (_, guard) = crate::logging::init_logging(&logging_opts, "info");
|
let (_, guard) = crate::logging::init_logging(&logging_opts, &initial_filter_spec);
|
||||||
_logging_guard = Some(guard);
|
_logging_guard = Some(guard);
|
||||||
}
|
}
|
||||||
crate::logging::LogDestination::File { .. } => {
|
crate::logging::LogDestination::File { .. } => {
|
||||||
@@ -365,7 +367,7 @@ async fn run_telemt_core(
|
|||||||
destination: log_destination,
|
destination: log_destination,
|
||||||
disable_colors: true,
|
disable_colors: true,
|
||||||
};
|
};
|
||||||
let (_, guard) = crate::logging::init_logging(&logging_opts, "info");
|
let (_, guard) = crate::logging::init_logging(&logging_opts, &initial_filter_spec);
|
||||||
_logging_guard = Some(guard);
|
_logging_guard = Some(guard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,7 +379,7 @@ async fn run_telemt_core(
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
info!("Telemt MTProxy v{}", env!("CARGO_PKG_VERSION"));
|
print_maestro_line(format!("Telemt MTProxy v{}", env!("CARGO_PKG_VERSION")));
|
||||||
info!("Log level: {}", effective_log_level);
|
info!("Log level: {}", effective_log_level);
|
||||||
if config.general.disable_colors {
|
if config.general.disable_colors {
|
||||||
info!("Colors: disabled");
|
info!("Colors: disabled");
|
||||||
|
|||||||
@@ -319,13 +319,7 @@ pub(crate) async fn apply_runtime_log_filter(
|
|||||||
filter_handle: reload::Handle<EnvFilter, tracing_subscriber::Registry>,
|
filter_handle: reload::Handle<EnvFilter, tracing_subscriber::Registry>,
|
||||||
mut log_level_rx: watch::Receiver<LogLevel>,
|
mut log_level_rx: watch::Receiver<LogLevel>,
|
||||||
) {
|
) {
|
||||||
let runtime_filter = if has_rust_log {
|
let runtime_filter = EnvFilter::new(log_filter_spec(has_rust_log, effective_log_level));
|
||||||
EnvFilter::from_default_env()
|
|
||||||
} else if matches!(effective_log_level, LogLevel::Silent) {
|
|
||||||
EnvFilter::new("warn,telemt::links=info")
|
|
||||||
} else {
|
|
||||||
EnvFilter::new(effective_log_level.to_filter_str())
|
|
||||||
};
|
|
||||||
filter_handle
|
filter_handle
|
||||||
.reload(runtime_filter)
|
.reload(runtime_filter)
|
||||||
.expect("Failed to switch log filter");
|
.expect("Failed to switch log filter");
|
||||||
@@ -336,7 +330,7 @@ pub(crate) async fn apply_runtime_log_filter(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let level = log_level_rx.borrow_and_update().clone();
|
let level = log_level_rx.borrow_and_update().clone();
|
||||||
let new_filter = tracing_subscriber::EnvFilter::new(level.to_filter_str());
|
let new_filter = tracing_subscriber::EnvFilter::new(log_filter_spec(false, &level));
|
||||||
if let Err(e) = filter_handle.reload(new_filter) {
|
if let Err(e) = filter_handle.reload(new_filter) {
|
||||||
tracing::error!("config reload: failed to update log filter: {}", e);
|
tracing::error!("config reload: failed to update log filter: {}", e);
|
||||||
}
|
}
|
||||||
@@ -344,6 +338,17 @@ pub(crate) async fn apply_runtime_log_filter(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn log_filter_spec(has_rust_log: bool, effective_log_level: &LogLevel) -> String {
|
||||||
|
if has_rust_log {
|
||||||
|
std::env::var("RUST_LOG")
|
||||||
|
.unwrap_or_else(|_| effective_log_level.to_filter_str().to_string())
|
||||||
|
} else if matches!(effective_log_level, LogLevel::Silent) {
|
||||||
|
"warn,telemt::links=info".to_string()
|
||||||
|
} else {
|
||||||
|
effective_log_level.to_filter_str().to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) async fn spawn_metrics_if_configured(
|
pub(crate) async fn spawn_metrics_if_configured(
|
||||||
config: &Arc<ProxyConfig>,
|
config: &Arc<ProxyConfig>,
|
||||||
startup_tracker: &Arc<StartupTracker>,
|
startup_tracker: &Arc<StartupTracker>,
|
||||||
|
|||||||
Reference in New Issue
Block a user