]> Humopery - fcgisrv.git/commitdiff
Replace println with logging
authorErik Mackdanz <erikmack@gmail.com>
Fri, 27 Oct 2023 02:50:55 +0000 (21:50 -0500)
committerErik Mackdanz <erikmack@gmail.com>
Fri, 27 Oct 2023 02:50:55 +0000 (21:50 -0500)
Cargo.lock
Cargo.toml
src/main.rs

index b9f9cd7fb9c9d215531ea20dfe1487861602ee0b..4fad405029c7a3e8506e62bd335a348197f3a84a 100644 (file)
@@ -23,6 +23,15 @@ version = "0.1.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
 
+[[package]]
+name = "deranged"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3"
+dependencies = [
+ "powerfmt",
+]
+
 [[package]]
 name = "fastcgi"
 version = "1.0.0"
@@ -37,17 +46,31 @@ name = "fcgisrv"
 version = "0.1.0"
 dependencies = [
  "fastcgi",
+ "log",
  "mime",
  "new_mime_guess",
  "signal",
+ "simplelog",
 ]
 
+[[package]]
+name = "itoa"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
+
 [[package]]
 name = "libc"
 version = "0.2.149"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
 
+[[package]]
+name = "log"
+version = "0.4.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
+
 [[package]]
 name = "mime"
 version = "0.3.17"
@@ -77,6 +100,59 @@ dependencies = [
  "void",
 ]
 
+[[package]]
+name = "num_threads"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "powerfmt"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.190"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.190"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
 [[package]]
 name = "signal"
 version = "0.7.0"
@@ -87,6 +163,68 @@ dependencies = [
  "nix",
 ]
 
+[[package]]
+name = "simplelog"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "acee08041c5de3d5048c8b3f6f13fafb3026b24ba43c6a695a0c76179b844369"
+dependencies = [
+ "log",
+ "termcolor",
+ "time",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.38"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "termcolor"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "time"
+version = "0.3.30"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
+dependencies = [
+ "deranged",
+ "itoa",
+ "libc",
+ "num_threads",
+ "powerfmt",
+ "serde",
+ "time-core",
+ "time-macros",
+]
+
+[[package]]
+name = "time-core"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
+
+[[package]]
+name = "time-macros"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
+dependencies = [
+ "time-core",
+]
+
 [[package]]
 name = "unicase"
 version = "2.7.0"
@@ -96,6 +234,12 @@ dependencies = [
  "version_check",
 ]
 
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+
 [[package]]
 name = "version_check"
 version = "0.9.4"
@@ -107,3 +251,34 @@ name = "void"
 version = "1.0.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
index 62fe26ca3eeaea12f2d3d29706c898534870e7a2..7fa08c1c73c9bf2111aaeb545e0fc9e8d2741a6d 100644 (file)
@@ -7,6 +7,8 @@ edition = "2021"
 
 [dependencies]
 fastcgi = "1.0.0"
+log = "0.4.20"
 mime = "0.3.17"
 new_mime_guess = "4.0.1"
 signal = "0.7.0"
+simplelog = "0.12.1"
index f89a17a68dc36c2d03d9251e3cf9777dbe2ffbb8..aebe90909a9ea2c891650323baede0e64c845ee9 100644 (file)
@@ -1,6 +1,8 @@
 use fastcgi::{run_raw,Request};
+use log::{info,error};
 use mime;
 use new_mime_guess::from_path;
+use simplelog::{SimpleLogger,LevelFilter,Config};
 use std::error::Error;
 use std::fs::{File,metadata,remove_file};
 use std::io::{Read,Write};
@@ -19,14 +21,14 @@ macro_rules! write_err_resp {
                                       {}\n",
                   $status,$statusmess,"text/plain",$body)
        {
-           println!("Error was {}",e);
+           error!("Error was {}",e);
        }
     }
 }
 
 fn handle_req(mut req: Request) {
     // for (k,v) in req.params() {
-    //         println!("key {} has value {}",k,v);
+    //         error!("key {} has value {}",k,v);
     // }
 
     // require a method
@@ -60,7 +62,7 @@ fn handle_req(mut req: Request) {
        return;
     };
 
-    println!("len: {}, perms: {:?}, mime: {}",
+    info!("len: {}, perms: {:?}, mime: {}",
             metadata.len(),metadata.permissions(),mimestr);
 
     // std::fs::read to one large buffer
@@ -78,7 +80,7 @@ fn handle_req(mut req: Request) {
            if let Err(e) = write!(&mut req.stdout(),
                                   "Content-Type: {}\nContent-Length: {}\n\n",
                                   mimestr,metadata.len()) {
-               println!("Error was {}",e);
+               error!("Error was {}",e);
            }
        }
        is_first_write = false;
@@ -88,11 +90,11 @@ fn handle_req(mut req: Request) {
        }
 
        match req.stdout().write(&buf[0..n]) {
-           Ok(x) => {
-               println!("wrote {} bytes",x);
+           Ok(_x) => {
+               // info!("wrote {} bytes",x);
            },
            Err(e) => {
-               println!("Error was {}",e);
+               error!("Error was {}",e);
            }
        }
     }
@@ -101,18 +103,24 @@ fn handle_req(mut req: Request) {
 
 fn main() -> Result<(),Box<dyn Error>> {
 
+    // init logging
+    SimpleLogger::init(LevelFilter::Info,Config::default())?;
+
     let socketpath = "/tmp/fcgisocket";
 
     // handle Ctrl+C
     set_command_line("/bin/rm",["-f",socketpath],[("FOO","")]);
     let _ = set_handler(&[Signal::SIGINT],false);
 
+    // remove socket file
     let _ = remove_file(socketpath);
 
+    info!("Entering main loop");
     let listener = UnixListener::bind(socketpath).unwrap();
     run_raw(handle_req,listener.as_raw_fd());
 
-    let _ = remove_file(socketpath);
+    // Nothing after this is called
 
+    info!("Left main loop");
     Ok(())
 }