[READ-ONLY] Mirror of https://github.com/FoxxMD/docker-proxy-filter. Filter the contents of Docker API responses
docker docker-socket-proxy filter
0

Configure Feed

Select the types of activity you want to include in your feed.

std log to slog

FoxxMD (Oct 7, 2025, 7:19 PM UTC) cdffb5ce 1985703e

+186 -14
+163
Cargo.lock
··· 55 55 checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" 56 56 57 57 [[package]] 58 + name = "arc-swap" 59 + version = "1.7.1" 60 + source = "registry+https://github.com/rust-lang/crates.io-index" 61 + checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" 62 + 63 + [[package]] 58 64 name = "async-channel" 59 65 version = "2.5.0" 60 66 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 285 291 "dotenv", 286 292 "futures-util", 287 293 "http", 294 + "log", 288 295 "ntex", 289 296 "regex", 290 297 "reqwest", ··· 292 299 "serde_json", 293 300 "slog", 294 301 "slog-async", 302 + "slog-scope", 303 + "slog-stdlog", 295 304 "slog-term", 296 305 "url", 297 306 ] ··· 870 879 ] 871 880 872 881 [[package]] 882 + name = "lazy_static" 883 + version = "1.5.0" 884 + source = "registry+https://github.com/rust-lang/crates.io-index" 885 + checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" 886 + 887 + [[package]] 873 888 name = "libc" 874 889 version = "0.2.176" 875 890 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 892 907 version = "0.4.28" 893 908 source = "registry+https://github.com/rust-lang/crates.io-index" 894 909 checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" 910 + dependencies = [ 911 + "value-bag", 912 + ] 895 913 896 914 [[package]] 897 915 name = "memchr" ··· 1590 1608 ] 1591 1609 1592 1610 [[package]] 1611 + name = "serde_fmt" 1612 + version = "1.0.3" 1613 + source = "registry+https://github.com/rust-lang/crates.io-index" 1614 + checksum = "e1d4ddca14104cd60529e8c7f7ba71a2c8acd8f7f5cfcdc2faf97eeb7c3010a4" 1615 + dependencies = [ 1616 + "serde", 1617 + ] 1618 + 1619 + [[package]] 1593 1620 name = "serde_json" 1594 1621 version = "1.0.145" 1595 1622 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1681 1708 ] 1682 1709 1683 1710 [[package]] 1711 + name = "slog-scope" 1712 + version = "4.4.0" 1713 + source = "registry+https://github.com/rust-lang/crates.io-index" 1714 + checksum = "2f95a4b4c3274cd2869549da82b57ccc930859bdbf5bcea0424bc5f140b3c786" 1715 + dependencies = [ 1716 + "arc-swap", 1717 + "lazy_static", 1718 + "slog", 1719 + ] 1720 + 1721 + [[package]] 1722 + name = "slog-stdlog" 1723 + version = "4.1.1" 1724 + source = "registry+https://github.com/rust-lang/crates.io-index" 1725 + checksum = "6706b2ace5bbae7291d3f8d2473e2bfab073ccd7d03670946197aec98471fa3e" 1726 + dependencies = [ 1727 + "log", 1728 + "slog", 1729 + "slog-scope", 1730 + ] 1731 + 1732 + [[package]] 1684 1733 name = "slog-term" 1685 1734 version = "2.9.2" 1686 1735 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1733 1782 checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" 1734 1783 1735 1784 [[package]] 1785 + name = "sval" 1786 + version = "2.15.0" 1787 + source = "registry+https://github.com/rust-lang/crates.io-index" 1788 + checksum = "d94c4464e595f0284970fd9c7e9013804d035d4a61ab74b113242c874c05814d" 1789 + 1790 + [[package]] 1791 + name = "sval_buffer" 1792 + version = "2.15.0" 1793 + source = "registry+https://github.com/rust-lang/crates.io-index" 1794 + checksum = "a0f46e34b20a39e6a2bf02b926983149b3af6609fd1ee8a6e63f6f340f3e2164" 1795 + dependencies = [ 1796 + "sval", 1797 + "sval_ref", 1798 + ] 1799 + 1800 + [[package]] 1801 + name = "sval_dynamic" 1802 + version = "2.15.0" 1803 + source = "registry+https://github.com/rust-lang/crates.io-index" 1804 + checksum = "03d0970e53c92ab5381d3b2db1828da8af945954d4234225f6dd9c3afbcef3f5" 1805 + dependencies = [ 1806 + "sval", 1807 + ] 1808 + 1809 + [[package]] 1810 + name = "sval_fmt" 1811 + version = "2.15.0" 1812 + source = "registry+https://github.com/rust-lang/crates.io-index" 1813 + checksum = "43e5e6e1613e1e7fc2e1a9fdd709622e54c122ceb067a60d170d75efd491a839" 1814 + dependencies = [ 1815 + "itoa", 1816 + "ryu", 1817 + "sval", 1818 + ] 1819 + 1820 + [[package]] 1821 + name = "sval_json" 1822 + version = "2.15.0" 1823 + source = "registry+https://github.com/rust-lang/crates.io-index" 1824 + checksum = "aec382f7bfa6e367b23c9611f129b94eb7daaf3d8fae45a8d0a0211eb4d4c8e6" 1825 + dependencies = [ 1826 + "itoa", 1827 + "ryu", 1828 + "sval", 1829 + ] 1830 + 1831 + [[package]] 1832 + name = "sval_nested" 1833 + version = "2.15.0" 1834 + source = "registry+https://github.com/rust-lang/crates.io-index" 1835 + checksum = "3049d0f99ce6297f8f7d9953b35a0103b7584d8f638de40e64edb7105fa578ae" 1836 + dependencies = [ 1837 + "sval", 1838 + "sval_buffer", 1839 + "sval_ref", 1840 + ] 1841 + 1842 + [[package]] 1843 + name = "sval_ref" 1844 + version = "2.15.0" 1845 + source = "registry+https://github.com/rust-lang/crates.io-index" 1846 + checksum = "f88913e77506085c0a8bf6912bb6558591a960faf5317df6c1d9b227224ca6e1" 1847 + dependencies = [ 1848 + "sval", 1849 + ] 1850 + 1851 + [[package]] 1852 + name = "sval_serde" 1853 + version = "2.15.0" 1854 + source = "registry+https://github.com/rust-lang/crates.io-index" 1855 + checksum = "f579fd7254f4be6cd7b450034f856b78523404655848789c451bacc6aa8b387d" 1856 + dependencies = [ 1857 + "serde_core", 1858 + "sval", 1859 + "sval_nested", 1860 + ] 1861 + 1862 + [[package]] 1736 1863 name = "syn" 1737 1864 version = "1.0.109" 1738 1865 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2055 2182 version = "1.0.4" 2056 2183 source = "registry+https://github.com/rust-lang/crates.io-index" 2057 2184 checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" 2185 + 2186 + [[package]] 2187 + name = "value-bag" 2188 + version = "1.11.1" 2189 + source = "registry+https://github.com/rust-lang/crates.io-index" 2190 + checksum = "943ce29a8a743eb10d6082545d861b24f9d1b160b7d741e0f2cdf726bec909c5" 2191 + dependencies = [ 2192 + "value-bag-serde1", 2193 + "value-bag-sval2", 2194 + ] 2195 + 2196 + [[package]] 2197 + name = "value-bag-serde1" 2198 + version = "1.11.1" 2199 + source = "registry+https://github.com/rust-lang/crates.io-index" 2200 + checksum = "35540706617d373b118d550d41f5dfe0b78a0c195dc13c6815e92e2638432306" 2201 + dependencies = [ 2202 + "erased-serde", 2203 + "serde", 2204 + "serde_fmt", 2205 + ] 2206 + 2207 + [[package]] 2208 + name = "value-bag-sval2" 2209 + version = "1.11.1" 2210 + source = "registry+https://github.com/rust-lang/crates.io-index" 2211 + checksum = "6fe7e140a2658cc16f7ee7a86e413e803fc8f9b5127adc8755c19f9fefa63a52" 2212 + dependencies = [ 2213 + "sval", 2214 + "sval_buffer", 2215 + "sval_dynamic", 2216 + "sval_fmt", 2217 + "sval_json", 2218 + "sval_ref", 2219 + "sval_serde", 2220 + ] 2058 2221 2059 2222 [[package]] 2060 2223 name = "variadics_please"
+3
Cargo.toml
··· 7 7 dotenv = "0.15.0" 8 8 futures-util = "0.3.31" 9 9 http = "1.3.1" 10 + log = {version = "0.4.28", features = ["kv","kv_std"] } 10 11 ntex = { version = "2.16.0", features = ["tokio"] } 11 12 regex = "1.11.3" 12 13 reqwest = {version = "0.12.23", features = ["json"] } ··· 14 15 serde_json = "1.0.145" 15 16 slog = "2.8.0" 16 17 slog-async = "2.8.0" 18 + slog-scope = "4.4.0" 19 + slog-stdlog = "4.1.1" 17 20 slog-term = "2.9.2" 18 21 url = "2.5.7"
+20 -14
src/main.rs
··· 2 2 extern crate slog; 3 3 extern crate slog_async; 4 4 extern crate slog_term; 5 + extern crate slog_scope; 6 + extern crate slog_stdlog; 7 + #[macro_use] 8 + extern crate log; 5 9 6 10 use futures_util::TryStreamExt; 7 11 use ::http::StatusCode; ··· 79 83 client: web::types::State<http::Client>, 80 84 forward_url: web::types::State<url::Url>, 81 85 container_name: web::types::State<String>, 82 - log: web::types::State<Logger>, 86 + //log: web::types::State<Logger>, 83 87 scrub_env: web::types::State<bool>, 84 88 data: web::types::State<AppStateWithContainerMap> 85 89 ) -> Result<web::HttpResponse, web::Error> { ··· 93 97 .map_err(web::Error::from)?; 94 98 95 99 let mut client_resp = web::HttpResponse::build(res.status()); 96 - 97 - info!(log, "test"); 98 100 99 101 if res.status() == 200 { 100 102 ··· 115 117 Some (m) => { 116 118 let mut cm = data.container_map.lock().unwrap(); 117 119 if !cm.contains_key(&m.id) { 118 - let id_res = get_container_name(&forward_url.to_string(), &m.id, &log).await; 120 + let id_res = get_container_name(&forward_url.to_string(), &m.id).await; 119 121 match id_res { 120 122 Ok(id) => { 121 123 cm.insert(m.id.clone(), Some(id)); 122 124 } 123 125 Err(e) => { 124 - warn!(log, "Could not get container info"; "error" => %e); 126 + warn!("Could not get container info: {e}"); 125 127 cm.insert(m.id.clone(), None); 126 128 } 127 129 } ··· 211 213 })); 212 214 } 213 215 214 - async fn get_container_name(u: &String, container_id: &String, log: &Logger) -> Result<String, Box<dyn std::error::Error>> { 216 + async fn get_container_name(u: &String, container_id: &String) -> Result<String, Box<dyn std::error::Error>> { 215 217 216 218 let url = format!("{}containers/{id}/json", u, id = container_id); 217 219 //debug!(log, "Get Container URL: {}", url); ··· 244 246 let decorator = slog_term::TermDecorator::new().build(); 245 247 let drain = slog_term::FullFormat::new(decorator).build().fuse(); 246 248 let drain = slog_async::Async::new(drain).build().fuse(); 247 - let log = slog::Logger::root(drain, o!()); 249 + let logger = slog::Logger::root(drain, o!()); 250 + 251 + let _guard = slog_scope::set_global_logger(logger); 252 + slog_scope::scope(&slog_scope::logger().new(o!("scope" => "1")), || ()); 253 + let _log_guard = slog_stdlog::init().unwrap(); 248 254 249 255 dotenv().ok(); 250 256 ··· 254 260 255 261 match proxy_url_env { 256 262 Ok(val) => { 257 - info!(log, "PROXY_URL: {}", val); 263 + info!("PROXY_URL: {val}"); 258 264 proxy_url.push_str(&val); 259 265 }, 260 266 Err(e) => { 261 - crit!(log, "Missing PROXY_URL"; "error" => %e); 267 + error!("Missing PROXY_URL"); 262 268 panic!(); 263 269 }, 264 270 } ··· 268 274 269 275 match container_name_env { 270 276 Ok(val) => { 271 - info!(log, "CONTAINER_NAME: {}", val); 277 + info!("CONTAINER_NAME: {val}"); 272 278 container_name.push_str(&val); 273 279 }, 274 280 Err(e) => { 275 - crit!(log, "Missing CONTAINER_NAME"; "error" => %e); 281 + error!("Missing CONTAINER_NAME"); 276 282 panic!(); 277 283 }, 278 284 } ··· 280 286 let scub_env = match env::var("SCRUB_ENVS") { 281 287 Ok(val) => { 282 288 let truthy = val == "true"; 283 - info!(log, "SCRUB_ENVS: {}", truthy); 289 + info!("SCRUB_ENVS: {truthy}"); 284 290 truthy 285 291 }, 286 292 Err(e) => { 287 - info!(log, "SCRUB_ENVS: false"); 293 + info!("SCRUB_ENVS: false"); 288 294 false 289 295 }, 290 296 }; ··· 300 306 .state(http::Client::new()) 301 307 .state(forward_url.clone()) 302 308 .state(container_name.clone()) 303 - .state(log.clone()) 309 + //.state(logger.clone()) 304 310 .state(cm.clone()) 305 311 .state(scub_env.clone()) 306 312 .wrap(web::middleware::Logger::default())