neon_arch commited on
Commit
bb61ee3
2 Parent(s): 0d1213a 3060b01

Merge branch 'logging' into 'rolling'

Browse files

add logging middleware

See merge request NEON-MMD/websurfx!1

Files changed (3) hide show
  1. Cargo.lock +30 -0
  2. Cargo.toml +2 -0
  3. src/bin/websurfx.rs +6 -2
Cargo.lock CHANGED
@@ -758,6 +758,19 @@ dependencies = [
758
  "cfg-if 1.0.0",
759
  ]
760
 
 
 
 
 
 
 
 
 
 
 
 
 
 
761
  [[package]]
762
  name = "errno"
763
  version = "0.3.1"
@@ -1174,6 +1187,12 @@ version = "1.0.2"
1174
  source = "registry+https://github.com/rust-lang/crates.io-index"
1175
  checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
1176
 
 
 
 
 
 
 
1177
  [[package]]
1178
  name = "hyper"
1179
  version = "0.12.36"
@@ -2775,6 +2794,15 @@ dependencies = [
2775
  "utf-8",
2776
  ]
2777
 
 
 
 
 
 
 
 
 
 
2778
  [[package]]
2779
  name = "thiserror"
2780
  version = "1.0.40"
@@ -3324,8 +3352,10 @@ dependencies = [
3324
  "actix-files",
3325
  "actix-web",
3326
  "clap",
 
3327
  "fake-useragent",
3328
  "handlebars",
 
3329
  "reqwest 0.11.16",
3330
  "scraper",
3331
  "serde",
 
758
  "cfg-if 1.0.0",
759
  ]
760
 
761
+ [[package]]
762
+ name = "env_logger"
763
+ version = "0.10.0"
764
+ source = "registry+https://github.com/rust-lang/crates.io-index"
765
+ checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0"
766
+ dependencies = [
767
+ "humantime",
768
+ "is-terminal",
769
+ "log",
770
+ "regex",
771
+ "termcolor",
772
+ ]
773
+
774
  [[package]]
775
  name = "errno"
776
  version = "0.3.1"
 
1187
  source = "registry+https://github.com/rust-lang/crates.io-index"
1188
  checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
1189
 
1190
+ [[package]]
1191
+ name = "humantime"
1192
+ version = "2.1.0"
1193
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1194
+ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
1195
+
1196
  [[package]]
1197
  name = "hyper"
1198
  version = "0.12.36"
 
2794
  "utf-8",
2795
  ]
2796
 
2797
+ [[package]]
2798
+ name = "termcolor"
2799
+ version = "1.2.0"
2800
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2801
+ checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
2802
+ dependencies = [
2803
+ "winapi-util",
2804
+ ]
2805
+
2806
  [[package]]
2807
  name = "thiserror"
2808
  version = "1.0.40"
 
3352
  "actix-files",
3353
  "actix-web",
3354
  "clap",
3355
+ "env_logger",
3356
  "fake-useragent",
3357
  "handlebars",
3358
+ "log",
3359
  "reqwest 0.11.16",
3360
  "scraper",
3361
  "serde",
Cargo.toml CHANGED
@@ -16,3 +16,5 @@ actix-files = {version="0.6.2"}
16
  serde_json = {version="*"}
17
  fake-useragent = {version="*"}
18
  clap = {version="*", features = ["derive"] }
 
 
 
16
  serde_json = {version="*"}
17
  fake-useragent = {version="*"}
18
  clap = {version="*", features = ["derive"] }
19
+ env_logger = "0.10.0"
20
+ log = "0.4.17"
src/bin/websurfx.rs CHANGED
@@ -3,8 +3,9 @@ use std::ops::RangeInclusive;
3
  use websurfx::server::routes;
4
 
5
  use actix_files as fs;
6
- use actix_web::{web, App, HttpServer};
7
  use clap::{command, Parser};
 
8
  use handlebars::Handlebars;
9
 
10
  #[derive(Parser, Debug, Default)]
@@ -38,7 +39,9 @@ fn is_port_in_range(s: &str) -> Result<u16, String> {
38
  async fn main() -> std::io::Result<()> {
39
  let args = CliArgs::parse();
40
 
41
- println!("started server on port {}", args.port);
 
 
42
 
43
  let mut handlebars: Handlebars = Handlebars::new();
44
 
@@ -51,6 +54,7 @@ async fn main() -> std::io::Result<()> {
51
  HttpServer::new(move || {
52
  App::new()
53
  .app_data(handlebars_ref.clone())
 
54
  // Serve images and static files (css and js files).
55
  .service(fs::Files::new("/static", "./public/static").show_files_listing())
56
  .service(fs::Files::new("/images", "./public/images").show_files_listing())
 
3
  use websurfx::server::routes;
4
 
5
  use actix_files as fs;
6
+ use actix_web::{middleware::Logger, web, App, HttpServer};
7
  use clap::{command, Parser};
8
+ use env_logger::Env;
9
  use handlebars::Handlebars;
10
 
11
  #[derive(Parser, Debug, Default)]
 
39
  async fn main() -> std::io::Result<()> {
40
  let args = CliArgs::parse();
41
 
42
+ env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
43
+
44
+ log::info!("started server on port {}", args.port);
45
 
46
  let mut handlebars: Handlebars = Handlebars::new();
47
 
 
54
  HttpServer::new(move || {
55
  App::new()
56
  .app_data(handlebars_ref.clone())
57
+ .wrap(Logger::default())
58
  // Serve images and static files (css and js files).
59
  .service(fs::Files::new("/static", "./public/static").show_files_listing())
60
  .service(fs::Files::new("/images", "./public/images").show_files_listing())