diff options
author | Jake McGinty <me@jake.su> | 2018-03-01 19:57:47 +0000 |
---|---|---|
committer | Jake McGinty <me@jake.su> | 2018-03-04 01:23:25 +0000 |
commit | 295c7438c381ca2dae628d47a9b77138f7d413cd (patch) | |
tree | 802b140da4d03a8f9df315ecd4f41473d642250e | |
parent | peer: smaller allocations for incoming messages (diff) | |
download | wireguard-rs-295c7438c381ca2dae628d47a9b77138f7d413cd.tar.xz wireguard-rs-295c7438c381ca2dae628d47a9b77138f7d413cd.zip |
global: clean up logging, stop using env_logger
-rw-r--r-- | Cargo.lock | 35 | ||||
-rw-r--r-- | Cargo.toml | 12 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/main.rs | 27 | ||||
-rw-r--r-- | src/peer.rs | 5 |
5 files changed, 57 insertions, 23 deletions
@@ -163,6 +163,14 @@ dependencies = [ ] [[package]] +name = "colored" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "constant_time_eq" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -280,15 +288,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "env_logger" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "failure" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -308,6 +307,15 @@ dependencies = [ ] [[package]] +name = "fern" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "filetime" version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1282,14 +1290,16 @@ dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "chacha20-poly1305-aead 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "daemonize 0.2.3 (git+https://github.com/mcginty/daemonize)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fern 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "pnet_packet 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1380,6 +1390,7 @@ dependencies = [ "checksum chacha20-poly1305-aead 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77d2058ba29594f69c75e8a9018e0485e3914ca5084e3613cd64529042f5423b" "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" "checksum clap 2.30.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1c07b9257a00f3fc93b7f3c417fc15607ec7a56823bc2c37ec744e266387de5b" +"checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "checksum criterion 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e8852a0db5351470bbae05adaf2f8247eb50bf61abad84dcddad025157a916c" "checksum criterion-plot 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f69a0a6c7232793bcb84a5c3a97bc4d4476905ec50d836f589e1e67faeb497" @@ -1392,9 +1403,9 @@ dependencies = [ "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" -"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82" "checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b" +"checksum fern 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "50475651fccc56343c766e4d1889428ea753308a977e1315db358ada28cc8c9d" "checksum filetime 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "714653f3e34871534de23771ac7b26e999651a0a228f47beb324dfdf1dd4b10f" "checksum fsevent 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "c4bbbf71584aeed076100b5665ac14e3d85eeb31fdbb45fbd41ef9a682b5ec05" "checksum fsevent-sys 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1a772d36c338d07a032d5375a36f15f9a7043bf0cb8ce7cee658e037c6032874" @@ -13,10 +13,10 @@ path = "src/lib.rs" [[bin]] name = "wgrs" path = "src/main.rs" -required-features = ["build-binary"] +required-features = ["binary"] [features] -build-binary = [ "daemonize", "structopt", "structopt-derive" ] +binary = [ "daemonize", "structopt", "structopt-derive", "fern", "chrono", "colored" ] [profile.release] debug = true @@ -34,11 +34,10 @@ blake2-rfc = "0.2" byteorder = "^1.2" bytes = "0.4" chacha20-poly1305-aead = "^0.1" -env_logger = "^0.4" failure = "^0.1" futures = "^0.1" lazy_static = "^1" -log = "^0.3" +log = "^0.4" hex = "^0.3" notify = "4.0.0" rand = "^0.4" @@ -56,6 +55,9 @@ tokio-signal = "^0.1" treebitmap = "^0.2" x25519-dalek = "^0.1" -daemonize = { git = "https://github.com/mcginty/daemonize", version = "0.2", optional = true } +daemonize = { git = "https://github.com/mcginty/daemonize", optional = true } +chrono = { version = "^0.4", optional = true } +colored = { version = "^1.6", optional = true } structopt = { version = "^0.1", optional = true } structopt-derive = { version = "^0.1", optional = true } +fern = { version = "^0.5", features = ["colored"], optional = true } @@ -15,7 +15,6 @@ extern crate blake2_rfc; extern crate byteorder; extern crate bytes; extern crate chacha20_poly1305_aead; -extern crate env_logger; extern crate futures; extern crate hex; extern crate nix; diff --git a/src/main.rs b/src/main.rs index 515b16b..b347d0d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,14 +4,17 @@ #[macro_use] extern crate structopt_derive; #[macro_use] extern crate log; +extern crate chrono; +extern crate colored; extern crate daemonize; -extern crate env_logger; +extern crate fern; extern crate nix; extern crate structopt; extern crate wireguard; use daemonize::Daemonize; use failure::Error; +use fern::colors::{Color, ColoredLevelConfig}; use wireguard::interface::Interface; use structopt::StructOpt; @@ -37,7 +40,27 @@ struct Opt { } fn main() { - env_logger::init().unwrap(); + let colors = ColoredLevelConfig::new() + .debug(Color::Magenta) + .info(Color::BrightBlue) + .warn(Color::BrightYellow) + .error(Color::BrightRed); + fern::Dispatch::new() + .format(move |out, message, record| { + let pad = record.level() == log::Level::Warn || record.level() == log::Level::Info; + out.finish(format_args!( + "{} {}{} {}", + chrono::Local::now().format("%H:%M:%S%.3f"), + colors.color(record.level()), + if pad { " " } else { "" }, + message, + )) + }) + .level(log::LevelFilter::Info) + .level_for("wireguard", log::LevelFilter::Debug) + .chain(std::io::stdout()) + .apply().unwrap(); + let opt = Opt::from_args(); if !opt.foreground { diff --git a/src/peer.rs b/src/peer.rs index 4b5135d..e6712ed 100644 --- a/src/peer.rs +++ b/src/peer.rs @@ -1,8 +1,7 @@ use anti_replay::AntiReplay; use byteorder::{ByteOrder, LittleEndian}; -use consts::{TRANSPORT_OVERHEAD, TRANSPORT_HEADER_SIZE, MAX_SEGMENT_SIZE, REKEY_AFTER_MESSAGES, - REKEY_AFTER_TIME, REKEY_AFTER_TIME_RECV, REJECT_AFTER_TIME, REJECT_AFTER_MESSAGES, - PADDING_MULTIPLE}; +use consts::{TRANSPORT_OVERHEAD, TRANSPORT_HEADER_SIZE, REKEY_AFTER_MESSAGES, REKEY_AFTER_TIME, + REKEY_AFTER_TIME_RECV, REJECT_AFTER_TIME, REJECT_AFTER_MESSAGES, PADDING_MULTIPLE}; use cookie; use failure::{Error, err_msg}; use interface::UtunPacket; |