Skip to main content

init

Function init 

Source
pub fn init()
Expand description

Install the global logger. RUST_LOG keeps env_logger’s directive syntax (e.g. httpcan=debug,actix_server=off); the default level is info, so per-request access logs stay visible out of the box.

Examples found in repository?
examples/basic.rs (line 8)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    // Initialize logging (non-blocking stderr logger; RUST_LOG applies)
8    httpcan::logging::init();
9
10    // Method 1: Using default configuration
11    println!("Starting HTTPCan server with default configuration...");
12
13    // Create server with default settings (port 8080, all features enabled)
14    let _server = HttpCanServer::new();
15
16    // Method 2: Using builder pattern
17    let server = HttpCanServer::new()
18        .port(3000)
19        .host("127.0.0.1")
20        .add_current_server(true)
21        .exclude_header("x-internal-header")
22        .exclude_header("x-debug-*");
23
24    // Method 3: Using ServerConfig
25    let config = ServerConfig::new()
26        .port(3000)
27        .host("127.0.0.1")
28        .add_current_server(true)
29        .exclude_headers(vec![
30            "x-internal-header".to_string(),
31            "x-debug-*".to_string(),
32        ]);
33
34    let _server_with_config = HttpCanServer::with_config(config);
35
36    // Start the server
37    server.run().await?;
38
39    Ok(())
40}