Merge pull request #190 from vbrandl/feature/structured-logging

Feature/structured logging
This commit is contained in:
Valentin Brandl 2020-10-30 13:24:45 +01:00 committed by GitHub
commit 2d46592c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 262 additions and 247 deletions

377
Cargo.lock generated
View File

@ -170,6 +170,19 @@ dependencies = [
"pin-project 0.4.23", "pin-project 0.4.23",
] ]
[[package]]
name = "actix-slog"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c697a62a2f51c5c26af6b1dded0622f15bec690da191615947e0c1b2b7b75198"
dependencies = [
"actix-web",
"chrono",
"futures",
"pin-project 0.4.23",
"slog",
]
[[package]] [[package]]
name = "actix-testing" name = "actix-testing"
version = "1.0.0" version = "1.0.0"
@ -196,7 +209,7 @@ dependencies = [
"lazy_static", "lazy_static",
"log", "log",
"num_cpus", "num_cpus",
"parking_lot 0.10.0", "parking_lot",
"threadpool", "threadpool",
] ]
@ -336,6 +349,12 @@ version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" checksum = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff"
[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.4.12" version = "0.4.12"
@ -345,6 +364,12 @@ dependencies = [
"nodrop", "nodrop",
] ]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.40" version = "0.1.40"
@ -447,6 +472,17 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blake2b_simd"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a"
dependencies = [
"arrayref",
"arrayvec 0.5.2",
"constant_time_eq",
]
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.9.0" version = "0.9.0"
@ -541,13 +577,15 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.10" version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [ dependencies = [
"libc",
"num-integer", "num-integer",
"num-traits", "num-traits",
"time 0.1.42", "time 0.1.44",
"winapi 0.3.8",
] ]
[[package]] [[package]]
@ -574,21 +612,18 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "cloudabi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "const_fn" name = "const_fn"
version = "0.4.2" version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2" checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2"
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]] [[package]]
name = "cookie" name = "cookie"
version = "0.14.2" version = "0.14.2"
@ -637,6 +672,27 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crossbeam-channel"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
dependencies = [
"crossbeam-utils",
"maybe-uninit",
]
[[package]]
name = "crossbeam-utils"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
dependencies = [
"autocfg",
"cfg-if",
"lazy_static",
]
[[package]] [[package]]
name = "derive_more" name = "derive_more"
version = "0.99.2" version = "0.99.2"
@ -657,6 +713,27 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "dirs"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
dependencies = [
"cfg-if",
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.8",
]
[[package]] [[package]]
name = "discard" name = "discard"
version = "1.0.4" version = "1.0.4"
@ -867,7 +944,7 @@ checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"wasi", "wasi 0.9.0+wasi-snapshot-preview1",
] ]
[[package]] [[package]]
@ -927,14 +1004,13 @@ name = "hoc"
version = "0.14.3" version = "0.14.3"
dependencies = [ dependencies = [
"actix-rt", "actix-rt",
"actix-slog",
"actix-web", "actix-web",
"badge", "badge",
"bytes 0.6.0", "bytes 0.6.0",
"futures", "futures",
"git2", "git2",
"lazy_static", "lazy_static",
"log",
"log4rs",
"number_prefix", "number_prefix",
"openssl-probe", "openssl-probe",
"reqwest", "reqwest",
@ -942,6 +1018,10 @@ dependencies = [
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"slog",
"slog-async",
"slog-atomic",
"slog-term",
"structopt", "structopt",
"tempfile", "tempfile",
"vergen", "vergen",
@ -984,15 +1064,6 @@ version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9"
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
]
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.13.4" version = "0.13.4"
@ -1011,7 +1082,7 @@ dependencies = [
"log", "log",
"net2", "net2",
"pin-project 0.4.23", "pin-project 0.4.23",
"time 0.1.42", "time 0.1.44",
"tokio", "tokio",
"tower-service", "tower-service",
"want", "want",
@ -1050,12 +1121,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "instant"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485"
[[package]] [[package]]
name = "iovec" name = "iovec"
version = "0.1.4" version = "0.1.4"
@ -1144,7 +1209,7 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304bccb228c4b020f3a4835d247df0a02a7c4686098d4167762cfbbe4c5cb14" checksum = "2304bccb228c4b020f3a4835d247df0a02a7c4686098d4167762cfbbe4c5cb14"
dependencies = [ dependencies = [
"arrayvec", "arrayvec 0.4.12",
"cfg-if", "cfg-if",
"rustc_version", "rustc_version",
"ryu", "ryu",
@ -1212,15 +1277,6 @@ dependencies = [
"scopeguard", "scopeguard",
] ]
[[package]]
name = "lock_api"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c"
dependencies = [
"scopeguard",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.11" version = "0.4.11"
@ -1228,38 +1284,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"serde",
]
[[package]]
name = "log-mdc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a94d21414c1f4a51209ad204c1776a3d0765002c76c6abcb602a6f09f1e881c7"
[[package]]
name = "log4rs"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1e1ad45e4584824d760c35d71868dd7e6e5acd8f5195a9573743b369fc86cd6"
dependencies = [
"arc-swap",
"chrono",
"flate2",
"fnv",
"humantime",
"libc",
"log",
"log-mdc",
"parking_lot 0.11.0",
"serde",
"serde-value",
"serde_derive",
"serde_json",
"serde_yaml",
"thread-id",
"typemap",
"winapi 0.3.8",
] ]
[[package]] [[package]]
@ -1277,6 +1301,12 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]] [[package]]
name = "md5" name = "md5"
version = "0.7.0" version = "0.7.0"
@ -1492,15 +1522,6 @@ dependencies = [
"vcpkg", "vcpkg",
] ]
[[package]]
name = "ordered-float"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "owned_ttf_parser" name = "owned_ttf_parser"
version = "0.6.0" version = "0.6.0"
@ -1516,19 +1537,8 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc"
dependencies = [ dependencies = [
"lock_api 0.3.3", "lock_api",
"parking_lot_core 0.7.0", "parking_lot_core",
]
[[package]]
name = "parking_lot"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733"
dependencies = [
"instant",
"lock_api 0.4.1",
"parking_lot_core 0.8.0",
] ]
[[package]] [[package]]
@ -1538,22 +1548,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7582838484df45743c8434fbff785e8edf260c28748353d44bc0da32e0ceabf1" checksum = "7582838484df45743c8434fbff785e8edf260c28748353d44bc0da32e0ceabf1"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"cloudabi 0.0.3", "cloudabi",
"libc",
"redox_syscall",
"smallvec",
"winapi 0.3.8",
]
[[package]]
name = "parking_lot_core"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b"
dependencies = [
"cfg-if",
"cloudabi 0.1.0",
"instant",
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
@ -1744,6 +1739,17 @@ version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
[[package]]
name = "redox_users"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
dependencies = [
"getrandom",
"redox_syscall",
"rust-argon2",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.3.4" version = "1.3.4"
@ -1829,6 +1835,18 @@ dependencies = [
"nom 5.1.0", "nom 5.1.0",
] ]
[[package]]
name = "rust-argon2"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19"
dependencies = [
"base64",
"blake2b_simd",
"constant_time_eq",
"crossbeam-utils",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.16" version = "0.1.16"
@ -1921,16 +1939,6 @@ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]]
name = "serde-value"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a65a7291a8a568adcae4c10a677ebcedbc6c9cec91c054dee2ce40b0e3290eb"
dependencies = [
"ordered-float",
"serde",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.117" version = "1.0.117"
@ -1965,18 +1973,6 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "serde_yaml"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "691b17f19fc1ec9d94ec0b5864859290dff279dbd7b03f017afda54eb36c3c35"
dependencies = [
"dtoa",
"linked-hash-map",
"serde",
"yaml-rust",
]
[[package]] [[package]]
name = "sha-1" name = "sha-1"
version = "0.9.1" version = "0.9.1"
@ -2012,6 +2008,47 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "slog"
version = "2.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cc9c640a4adbfbcc11ffb95efe5aa7af7309e002adab54b185507dbf2377b99"
[[package]]
name = "slog-async"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b3336ce47ce2f96673499fc07eb85e3472727b9a7a2959964b002c2ce8fbbb"
dependencies = [
"crossbeam-channel",
"slog",
"take_mut",
"thread_local",
]
[[package]]
name = "slog-atomic"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87803759296346553aabece939e9ff174e7fc7ce2406c1fbd235b0c0a322523a"
dependencies = [
"arc-swap",
"slog",
]
[[package]]
name = "slog-term"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab1d807cf71129b05ce36914e1dbb6fbfbdecaf686301cb457f4fa967f9f5b6"
dependencies = [
"atty",
"chrono",
"slog",
"term",
"thread_local",
]
[[package]] [[package]]
name = "smallvec" name = "smallvec"
version = "1.4.1" version = "1.4.1"
@ -2149,6 +2186,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "take_mut"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
[[package]] [[package]]
name = "tempfile" name = "tempfile"
version = "3.1.0" version = "3.1.0"
@ -2163,6 +2206,16 @@ dependencies = [
"winapi 0.3.8", "winapi 0.3.8",
] ]
[[package]]
name = "term"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0863a3345e70f61d613eab32ee046ccd1bcc5f9105fe402c61fcd0c13eeb8b5"
dependencies = [
"dirs",
"winapi 0.3.8",
]
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.11.0"
@ -2192,17 +2245,6 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "thread-id"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fbf4c9d56b320106cd64fd024dadfa0be7cb4706725fc44a7d7ce952d820c1"
dependencies = [
"libc",
"redox_syscall",
"winapi 0.3.8",
]
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.0.1" version = "1.0.1"
@ -2223,12 +2265,12 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.1.42" version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [ dependencies = [
"libc", "libc",
"redox_syscall", "wasi 0.10.0+wasi-snapshot-preview1",
"winapi 0.3.8", "winapi 0.3.8",
] ]
@ -2350,12 +2392,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
[[package]]
name = "traitobject"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
[[package]] [[package]]
name = "trust-dns-proto" name = "trust-dns-proto"
version = "0.19.5" version = "0.19.5"
@ -2408,15 +2444,6 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc" checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc"
[[package]]
name = "typemap"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6"
dependencies = [
"unsafe-any",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.12.0" version = "1.12.0"
@ -2468,15 +2495,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "unsafe-any"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f"
dependencies = [
"traitobject",
]
[[package]] [[package]]
name = "url" name = "url"
version = "2.1.1" version = "2.1.1"
@ -2538,6 +2556,12 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.58" version = "0.2.58"
@ -2720,12 +2744,3 @@ dependencies = [
"winapi 0.2.8", "winapi 0.2.8",
"winapi-build", "winapi-build",
] ]
[[package]]
name = "yaml-rust"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d"
dependencies = [
"linked-hash-map",
]

View File

@ -6,22 +6,25 @@ edition = "2018"
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]
actix-rt = "1.1.1"
actix-slog = "0.2.1"
actix-web = "3.1.0" actix-web = "3.1.0"
badge = "0.3.0" badge = "0.3.0"
bytes = "0.6.0" bytes = "0.6.0"
futures = "0.3.7" futures = "0.3.7"
git2 = "0.13.12" git2 = "0.13.12"
lazy_static = "1.4.0" lazy_static = "1.4.0"
log = "0.4.11"
log4rs = "0.13.0"
number_prefix = "0.4.0" number_prefix = "0.4.0"
openssl-probe = "0.1.2" openssl-probe = "0.1.2"
reqwest = "0.10.8" reqwest = "0.10.8"
serde = "1.0.117" serde = "1.0.117"
serde_derive = "1.0.103" serde_derive = "1.0.103"
serde_json = "1.0.59" serde_json = "1.0.59"
slog = "2.5.2"
slog-async = "2.5.0"
slog-atomic = "3.0.0"
slog-term = "2.6.0"
structopt = "0.3.20" structopt = "0.3.20"
actix-rt = "1.1.1"
[build-dependencies] [build-dependencies]
ructe = "0.12.0" ructe = "0.12.0"

View File

@ -1,10 +1,5 @@
use crate::{error::Result, statics::OPT}; use slog::{Drain, Logger};
use log::LevelFilter; use slog_atomic::AtomicSwitch;
use log4rs::{
append::{console::ConsoleAppender, file::FileAppender},
config::{Appender, Config, Root},
encode::pattern::PatternEncoder,
};
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt; use structopt::StructOpt;
@ -38,33 +33,28 @@ pub(crate) struct Opt {
#[structopt(short = "w", long = "workers", default_value = "4")] #[structopt(short = "w", long = "workers", default_value = "4")]
/// Number of worker threads /// Number of worker threads
pub(crate) workers: usize, pub(crate) workers: usize,
#[structopt( // #[structopt(
short = "l", // short = "l",
long = "logfile", // long = "logfile",
parse(from_os_str), // parse(from_os_str),
default_value = "./hoc.log" // default_value = "./hoc.log"
)] // )]
/// The logfile // /// The logfile
pub(crate) logfile: PathBuf, // pub(crate) logfile: PathBuf,
} }
pub(crate) async fn init() -> Result<()> { pub(crate) fn init() -> Logger {
std::env::set_var("RUST_LOG", "actix_web=info,hoc=info"); std::env::set_var("RUST_LOG", "actix_web=info,hoc=info");
openssl_probe::init_ssl_cert_env_vars(); openssl_probe::init_ssl_cert_env_vars();
let stdout = ConsoleAppender::builder().build();
let file = FileAppender::builder() let decorator = slog_term::PlainDecorator::new(std::io::stdout());
.encoder(Box::new(PatternEncoder::new("{d} - {m}{n}"))) let drain = slog_term::FullFormat::new(decorator).build().fuse();
.build(&OPT.logfile) let drain = slog_async::Async::new(drain).build().fuse();
.unwrap(); let drain = AtomicSwitch::new(drain);
let config = Config::builder()
.appender(Appender::builder().build("stdout", Box::new(stdout))) let root = Logger::root(drain, o!("version" => env!("CARGO_PKG_VERSION")));
.appender(Appender::builder().build("file", Box::new(file)))
.build( info!(root, "Logging initialized");
Root::builder()
.appender("stdout") root
.appender("file")
.build(LevelFilter::Info),
)?;
log4rs::init_config(config)?;
Ok(())
} }

View File

@ -14,8 +14,6 @@ pub(crate) enum Error {
Git(git2::Error), Git(git2::Error),
Internal, Internal,
Io(std::io::Error), Io(std::io::Error),
Log(log::SetLoggerError),
LogBuilder(log4rs::config::Errors),
Parse(std::num::ParseIntError), Parse(std::num::ParseIntError),
Serial(serde_json::Error), Serial(serde_json::Error),
BranchNotFound, BranchNotFound,
@ -29,8 +27,6 @@ impl fmt::Display for Error {
Error::Git(e) => write!(fmt, "Git({})", e), Error::Git(e) => write!(fmt, "Git({})", e),
Error::Internal => write!(fmt, "Internal Error"), Error::Internal => write!(fmt, "Internal Error"),
Error::Io(e) => write!(fmt, "Io({})", e), Error::Io(e) => write!(fmt, "Io({})", e),
Error::Log(e) => write!(fmt, "Log({})", e),
Error::LogBuilder(e) => write!(fmt, "LogBuilder({})", e),
Error::Parse(e) => write!(fmt, "Parse({})", e), Error::Parse(e) => write!(fmt, "Parse({})", e),
Error::Serial(e) => write!(fmt, "Serial({})", e), Error::Serial(e) => write!(fmt, "Serial({})", e),
Error::BranchNotFound => write!(fmt, "Repo doesn't have master branch"), Error::BranchNotFound => write!(fmt, "Repo doesn't have master branch"),
@ -76,12 +72,6 @@ impl From<git2::Error> for Error {
} }
} }
impl From<log::SetLoggerError> for Error {
fn from(err: log::SetLoggerError) -> Self {
Error::Log(err)
}
}
impl From<std::io::Error> for Error { impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self { fn from(err: std::io::Error) -> Self {
Error::Io(err) Error::Io(err)
@ -100,12 +90,6 @@ impl From<reqwest::Error> for Error {
} }
} }
impl From<log4rs::config::Errors> for Error {
fn from(err: log4rs::config::Errors) -> Self {
Error::LogBuilder(err)
}
}
impl From<std::num::ParseIntError> for Error { impl From<std::num::ParseIntError> for Error {
fn from(err: std::num::ParseIntError) -> Self { fn from(err: std::num::ParseIntError) -> Self {
Error::Parse(err) Error::Parse(err)

View File

@ -4,10 +4,12 @@
extern crate actix_web; extern crate actix_web;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
#[macro_use] // #[macro_use]
extern crate log; // extern crate log;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use]
extern crate slog;
mod cache; mod cache;
mod config; mod config;
@ -35,6 +37,7 @@ use actix_web::{
use badge::{Badge, BadgeOptions}; use badge::{Badge, BadgeOptions};
use git2::{BranchType, Repository}; use git2::{BranchType, Repository};
use number_prefix::NumberPrefix; use number_prefix::NumberPrefix;
use slog::Logger;
use std::{ use std::{
borrow::Cow, borrow::Cow,
fs::create_dir_all, fs::create_dir_all,
@ -59,6 +62,7 @@ struct GeneratorForm<'a> {
pub(crate) struct State { pub(crate) struct State {
repos: String, repos: String,
cache: String, cache: String,
logger: Logger,
} }
#[derive(Serialize)] #[derive(Serialize)]
@ -81,7 +85,13 @@ fn pull(path: impl AsRef<Path>) -> Result<()> {
Ok(()) Ok(())
} }
fn hoc(repo: &str, repo_dir: &str, cache_dir: &str, branch: &str) -> Result<(u64, String, u64)> { fn hoc(
repo: &str,
repo_dir: &str,
cache_dir: &str,
branch: &str,
logger: &Logger,
) -> Result<(u64, String, u64)> {
let repo_dir = format!("{}/{}", repo_dir, repo); let repo_dir = format!("{}/{}", repo_dir, repo);
let cache_dir = format!("{}/{}.json", cache_dir, repo); let cache_dir = format!("{}/{}.json", cache_dir, repo);
let cache_dir = Path::new(&cache_dir); let cache_dir = Path::new(&cache_dir);
@ -108,16 +118,16 @@ fn hoc(repo: &str, repo_dir: &str, cache_dir: &str, branch: &str) -> Result<(u64
let cache = CacheState::read_from_file(&cache_dir, branch, &head)?; let cache = CacheState::read_from_file(&cache_dir, branch, &head)?;
match &cache { match &cache {
CacheState::Current { count, commits, .. } => { CacheState::Current { count, commits, .. } => {
info!("Using cache for {}", repo_dir); info!(logger, "Using cache");
return Ok((*count, head, *commits)); return Ok((*count, head, *commits));
} }
CacheState::Old { head, .. } => { CacheState::Old { head, .. } => {
info!("Updating cache for {}", repo_dir); info!(logger, "Updating cache");
arg.push(format!("{}..{}", head, branch)); arg.push(format!("{}..{}", head, branch));
arg_commit_count.push(format!("{}..{}", head, branch)); arg_commit_count.push(format!("{}..{}", head, branch));
} }
CacheState::No | CacheState::NoneForBranch(..) => { CacheState::No | CacheState::NoneForBranch(..) => {
info!("Creating cache for {}", repo_dir); info!(logger, "Creating cache");
arg.push(branch.to_string()); arg.push(branch.to_string());
arg_commit_count.push(branch.to_string()); arg_commit_count.push(branch.to_string());
} }
@ -180,13 +190,16 @@ where
T: Service, T: Service,
{ {
let data = data.into_inner(); let data = data.into_inner();
let logger = state
.logger
.new(o!("service" => T::domain(), "user" => data.0.clone(), "repo" => data.1.clone()));
let repo = format!( let repo = format!(
"{}/{}/{}", "{}/{}/{}",
T::domain(), T::domain(),
data.0.to_lowercase(), data.0.to_lowercase(),
data.1.to_lowercase() data.1.to_lowercase()
); );
info!("Deleting cache and repository for {}", repo); info!(logger, "Deleting cache and repository");
let cache_dir = format!("{}/{}.json", &state.cache, repo); let cache_dir = format!("{}/{}.json", &state.cache, repo);
let repo_dir = format!("{}/{}", &state.repos, repo); let repo_dir = format!("{}/{}", &state.repos, repo);
std::fs::remove_file(&cache_dir).or_else(|e| { std::fs::remove_file(&cache_dir).or_else(|e| {
@ -223,6 +236,9 @@ where
F: Fn(HocResult) -> Result<HttpResponse>, F: Fn(HocResult) -> Result<HttpResponse>,
{ {
let data = data.into_inner(); let data = data.into_inner();
let logger = state
.logger
.new(o!("service" => T::domain(), "user" => data.0.clone(), "repo" => data.1.clone(), "branch" => branch.to_string()));
let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase()); let repo = format!("{}/{}", data.0.to_lowercase(), data.1.to_lowercase());
let service_path = format!("{}/{}", T::url_path(), repo); let service_path = format!("{}/{}", T::url_path(), repo);
let service_url = format!("{}/{}", T::domain(), repo); let service_url = format!("{}/{}", T::domain(), repo);
@ -232,10 +248,10 @@ where
let file = Path::new(&path); let file = Path::new(&path);
if !file.exists() { if !file.exists() {
if !remote_exists { if !remote_exists {
warn!("Repository does not exist: {}", url); warn!(logger, "Repository does not exist");
return mapper(HocResult::NotFound); return mapper(HocResult::NotFound);
} }
info!("Cloning {} for the first time", url); info!(logger, "Cloning for the first time");
create_dir_all(file)?; create_dir_all(file)?;
let repo = Repository::init_bare(file)?; let repo = Repository::init_bare(file)?;
repo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*")?; repo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*")?;
@ -243,7 +259,7 @@ where
REPO_COUNT.fetch_add(1, Ordering::Relaxed); REPO_COUNT.fetch_add(1, Ordering::Relaxed);
} }
pull(&path)?; pull(&path)?;
let (hoc, head, commits) = hoc(&service_url, &state.repos, &state.cache, branch)?; let (hoc, head, commits) = hoc(&service_url, &state.repos, &state.cache, branch, &logger)?;
let hoc_pretty = match NumberPrefix::decimal(hoc as f64) { let hoc_pretty = match NumberPrefix::decimal(hoc as f64) {
NumberPrefix::Standalone(hoc) => hoc.to_string(), NumberPrefix::Standalone(hoc) => hoc.to_string(),
NumberPrefix::Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix), NumberPrefix::Prefixed(prefix, hoc) => format!("{:.1}{}", hoc, prefix),
@ -403,16 +419,19 @@ fn favicon32() -> HttpResponse {
HttpResponse::Ok().content_type("image/png").body(FAVICON) HttpResponse::Ok().content_type("image/png").body(FAVICON)
} }
async fn start_server() -> std::io::Result<()> { async fn start_server(logger: Logger) -> std::io::Result<()> {
let interface = format!("{}:{}", OPT.host, OPT.port); let interface = format!("{}:{}", OPT.host, OPT.port);
let state = Arc::new(State { let state = Arc::new(State {
repos: OPT.outdir.display().to_string(), repos: OPT.outdir.display().to_string(),
cache: OPT.cachedir.display().to_string(), cache: OPT.cachedir.display().to_string(),
logger,
}); });
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()
.data(state.clone()) .data(state.clone())
.wrap(middleware::Logger::default()) .wrap(actix_slog::StructuredLogger::new(
state.logger.new(o!("log_type" => "access")),
))
.wrap(middleware::NormalizePath::new(TrailingSlash::Trim)) .wrap(middleware::NormalizePath::new(TrailingSlash::Trim))
.service(index) .service(index)
.service(web::resource("/tacit-css.min.css").route(web::get().to(css))) .service(web::resource("/tacit-css.min.css").route(web::get().to(css)))
@ -450,6 +469,6 @@ async fn start_server() -> std::io::Result<()> {
#[actix_rt::main] #[actix_rt::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
config::init().await.unwrap(); let logger = config::init();
start_server().await start_server(logger).await
} }

View File

@ -23,7 +23,11 @@ macro_rules! test_service {
let cache_dir = dbg!(tempdir().unwrap()); let cache_dir = dbg!(tempdir().unwrap());
let repos = format!("{}/", repo_dir.path().display()); let repos = format!("{}/", repo_dir.path().display());
let cache = format!("{}/", cache_dir.path().display()); let cache = format!("{}/", cache_dir.path().display());
let state = dbg!(State { repos, cache }); let state = dbg!(State {
repos,
cache,
logger: crate::config::init(),
});
let mut app = test_app!(state, web::resource($path).to($what::<T>)); let mut app = test_app!(state, web::resource($path).to($what::<T>));