Added request logging

This commit is contained in:
Leonard Lorenz 2020-11-21 23:45:59 +01:00
parent 8f2512e95f
commit 818a7bb0a0
4 changed files with 85 additions and 38 deletions

View file

@ -1,41 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="{{ username }}' site'" />
<meta property="og:image" content="/static/site-image.png" />
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="{{ username }}' site'" />
<meta property="og:image" content="/static/site-image.png" />
<title>{{ username }}' site</title>
<link rel="stylesheet" href="/static/css/index.css">
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico"/>
</head>
<title>{{ username }}' site</title>
<link rel="stylesheet" href="/static/css/index.css">
<link rel="shortcut icon" type="image/jpg" href="/static/favicon.ico"/>
</head>
<body>
<h1>Hi, I'm {{ username }}</h1>
<p>
I have a <a href="/blog">blog.</a><br>
If you have questions or input for me please send me an E-Mail to {{ email }}
</p>
<br>
<p>
<ul style="list-style: none;">
{% if github_account %}
<li><img class="social-icon" src="https://github.com/favicon.ico"><a href="https://github.com/{{ github_account }}"> {{ github_account }}</a></li>
{% endif %}
{% if twitter_account %}
<li><img class="social-icon" src="https://twitter.com/favicon.ico"><a href="https://twitter.com/{{ twitter_account }}"> {{ twitter_account }}</a></li>
{% endif %}
{% if reddit_account %}
<li><img class="social-icon" src="https://reddit.com/favicon.ico"><a href="https://reddit.com/u/{{ reddit_account }}"> {{ reddit_account }}</a></li>
{% endif %}
{% if mastodon_account %}
<li><img class="social-icon" src="https://mastodon.social/favicon.ico"><a href="https://discord.com/"> {{ mastodon_account }}</a></li>
{% endif %}
{% if discord_account %}
<li><img class="social-icon" src="https://discord.com/assets/07dca80a102d4149e9736d4b162cff6f.ico"><a href="https://discord.com/"> {{ discord_account }}</a></li>
{% endif %}
</ul>
</p>
</body>
<body>
<h1>Hi, I'm {{ username }}</h1>
<p>
I have a <a href="/blog">blog.</a><br>
If you have questions or input for me please send me an E-Mail to {{ email }}
</p>
<br>
<p>
<ul style="list-style: none;">
{% if github_account %}
<li><img class="social-icon" src="https://github.com/favicon.ico"><a href="https://github.com/{{ github_account }}"> {{ github_account }}</a></li>
{% endif %}
{% if twitter_account %}
<li><img class="social-icon" src="https://twitter.com/favicon.ico"><a href="https://twitter.com/{{ twitter_account }}"> {{ twitter_account }}</a></li>
{% endif %}
{% if reddit_account %}
<li><img class="social-icon" src="https://reddit.com/favicon.ico"><a href="https://reddit.com/u/{{ reddit_account }}"> {{ reddit_account }}</a></li>
{% endif %}
{% if mastodon_account %}
<li><img class="social-icon" src="https://mastodon.social/favicon.ico"><a href="https://discord.com/"> {{ mastodon_account }}</a></li>
{% endif %}
{% if discord_account %}
<li><img class="social-icon" src="https://discord.com/assets/07dca80a102d4149e9736d4b162cff6f.ico"><a href="https://discord.com/"> {{ discord_account }}</a></li>
{% endif %}
</ul>
</p>
</body>
</html>

40
site/Cargo.lock generated
View file

@ -316,6 +316,17 @@ dependencies = [
"syn 1.0.48",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "autocfg"
version = "1.0.1"
@ -568,6 +579,7 @@ dependencies = [
"chrono",
"diesel 1.4.5",
"diesel_codegen",
"env_logger",
"once_cell",
"serde",
"serde_derive",
@ -715,6 +727,19 @@ dependencies = [
"syn 1.0.48",
]
[[package]]
name = "env_logger"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26ecb66b4bdca6c1409b40fb255eefc2bd4f6d135dab3c3124f80ffa2a9661e"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
@ -995,6 +1020,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e"
[[package]]
name = "humantime"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a"
[[package]]
name = "idna"
version = "0.2.0"
@ -1850,6 +1881,15 @@ dependencies = [
"unic-segment",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.22"

View file

@ -1,6 +1,6 @@
[package]
name = "crablog"
version = "0.2.1"
version = "0.2.2"
authors = ["Leonard Lorenz <dev@leonardlorenz.de>"]
edition = "2018"
@ -23,3 +23,5 @@ uuid = { version = "0.8.1", features = ["serde", "v5"] }
tera = "1.5.0"
once_cell = "1.5.2"
env_logger = "0.8.2"

View file

@ -9,7 +9,8 @@ extern crate serde_derive;
extern crate tera;
use actix_files as fs;
use actix_web::{App, HttpServer};
use actix_web::{App, HttpServer, middleware::Logger};
use env_logger::Env;
use tera::Tera;
use std::{env, sync::RwLock, collections::HashMap};
use once_cell::sync::Lazy;
@ -47,6 +48,9 @@ async fn main() -> std::io::Result<()> {
let mut tera = Tera::new(format!("{}{}", CONFIG_MAP.read().unwrap().get("ROOT_PATH").unwrap(), "/templates/*").as_str()).unwrap();
tera.autoescape_on(vec![".sql"]);
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
App::new()
.data(tera)
.service(routes::root)
@ -62,6 +66,7 @@ async fn main() -> std::io::Result<()> {
.service(api::blog_hide_post)
.service(api::blog_delete_post)
.service(fs::Files::new("/static", "../content/static"))
.wrap(Logger::new("%a %r %t"))
})
.bind(format!("0.0.0.0:{}", CONFIG_MAP.read().unwrap().get("BIND_PORT").unwrap()))?
.run()