Skip to main content

ws2tcp_local_core/
lib.rs

1use anyhow::{Result, anyhow};
2
3mod auth;
4mod gateway;
5mod http_proxy;
6mod routing_rules;
7pub mod service;
8pub mod settings;
9mod tls;
10mod tunnel;
11
12pub use service::{run_proxy, run_proxy_with_mode_updates};
13pub use settings::{
14    DEFAULT_BUFFER_SIZE, DEFAULT_LISTEN, DEFAULT_RULE_REFRESH_INTERVAL_SECS, ProxyMode, Settings,
15    SettingsOverrides,
16};
17
18pub fn init_logging(log_level: Option<&str>) -> Result<()> {
19    let filter = match log_level {
20        Some(filter) => filter.to_owned(),
21        None => std::env::var("RUST_LOG").unwrap_or_else(|_| "ws2tcp_local=info".to_owned()),
22    };
23
24    tracing_subscriber::fmt()
25        .with_env_filter(filter)
26        .try_init()
27        .or_else(|err| {
28            if err
29                .to_string()
30                .contains("global default trace dispatcher has already been set")
31            {
32                Ok(())
33            } else {
34                Err(anyhow!("failed to initialize logging: {err}"))
35            }
36        })
37}