Add syslog logging for sccache-dist. Fixes #380

This change adds a `--syslog=level` argument to the sccache-dist `scheduler`
and `server` commands that sends logs to syslog.
This commit is contained in:
Ted Mielczarek 2019-02-28 14:42:56 -05:00
Родитель 9b04c5857b
Коммит 3fc1b77a98
3 изменённых файлов: 57 добавлений и 11 удалений

30
Cargo.lock сгенерированный
Просмотреть файл

@ -442,6 +442,14 @@ dependencies = [
"termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "error-chain"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "error-chain"
version = "0.12.0"
@ -769,7 +777,7 @@ source = "git+https://github.com/Jake-Shadle/jsonwebtoken.git?rev=2f469a61#2f469
dependencies = [
"base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1579,7 +1587,7 @@ dependencies = [
[[package]]
name = "ring"
version = "0.13.2"
version = "0.13.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1714,7 +1722,7 @@ dependencies = [
"regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"retry 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rouille 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"selenium-rs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1722,6 +1730,7 @@ dependencies = [
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
"strip-ansi-escapes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syslog 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"tar 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1983,6 +1992,17 @@ dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syslog"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "tar"
version = "0.4.20"
@ -2686,6 +2706,7 @@ dependencies = [
"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
"checksum encoding_rs 0.8.10 (registry+https://github.com/rust-lang/crates.io-index)" = "065f4d0c826fdaef059ac45487169d918558e3cf86c9d89f6e81cf52369126e5"
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3"
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
"checksum escargot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19db1f7e74438642a5018cdf263bb1325b2e792f02dd0a3ca6d6c0f0d7b1d5a5"
"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
@ -2806,7 +2827,7 @@ dependencies = [
"checksum reqwest 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)" = "738769ec83daf6c1929dc9dae7d69ed3779b55ae5c356e989dcd3aa677d8486e"
"checksum reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ab52e462d1e15891441aeefadff68bdea005174328ce3da0a314f2ad313ec837"
"checksum retry 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "29460f6011a25fc70b22010e796bd98330baccaa0005cba6f90b858a510dec0d"
"checksum ring 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe642b9dd1ba0038d78c4a3999d1ee56178b4d415c1e1fbaba83b06dce012f0"
"checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a"
"checksum rouille 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0845b9c39ba772da769fe2aaa4d81bfd10695a7ea051d0510702260ff4159841"
"checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a"
"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395"
@ -2845,6 +2866,7 @@ dependencies = [
"checksum syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)" = "816b7af21405b011a23554ea2dc3f6576dc86ca557047c34098c1d741f10f823"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015"
"checksum syslog 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a0641142b4081d3d44beffa4eefd7346a228cdf91ed70186db2ca2cef762d327"
"checksum tar 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "a303ba60a099fcd2aaa646b14d2724591a96a75283e4b7ed3d1a1658909d9ae2"
"checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
"checksum tempfile 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "55c1195ef8513f3273d55ff59fe5da6940287a0d7a98331254397f464833675b"

Просмотреть файл

@ -86,6 +86,7 @@ crossbeam-utils = { version = "0.5", optional = true }
libmount = { version = "0.1.10", optional = true }
nix = { version = "0.11.0", optional = true }
rouille = { version = "2.2", optional = true, default-features = false, features = ["ssl"] }
syslog = { version = "4.0.1", optional = true }
void = { version = "1", optional = true }
[patch.crates-io]
@ -126,7 +127,7 @@ unstable = []
# Enables distributed support in the sccache client
dist-client = ["ar", "flate2", "hyper", "hyperx", "reqwest", "rust-crypto", "url"]
# Enables the sccache-dist binary
dist-server = ["arraydeque", "crossbeam-utils", "jsonwebtoken", "flate2", "libmount", "nix", "openssl", "reqwest", "rouille", "void"]
dist-server = ["arraydeque", "crossbeam-utils", "jsonwebtoken", "flate2", "libmount", "nix", "openssl", "reqwest", "rouille", "syslog", "void"]
# Enables dist tests with external requirements
dist-tests = []

Просмотреть файл

@ -21,11 +21,12 @@ extern crate sccache;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate syslog;
extern crate tar;
extern crate void;
use arraydeque::ArrayDeque;
use clap::{App, Arg, SubCommand};
use clap::{App, Arg, ArgMatches, SubCommand};
use rand::RngCore;
use sccache::config::{
scheduler as scheduler_config, server as server_config, INSECURE_DIST_CLIENT_TOKEN,
@ -45,6 +46,7 @@ use std::path::Path;
use std::sync::Mutex;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Instant;
use syslog::Facility;
use errors::*;
@ -124,6 +126,9 @@ fn main() {
});
}
/// These correspond to the values of `log::LevelFilter`.
const LOG_LEVELS: &[&str] = &["error", "warn", "info", "debug", "trace"];
pub fn get_app<'a, 'b>() -> App<'a, 'b> {
App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
@ -150,11 +155,27 @@ pub fn get_app<'a, 'b>() -> App<'a, 'b> {
).default_value("256"),
),
),
).subcommand(SubCommand::with_name("scheduler").arg(Arg::from_usage(
"--config <PATH> 'Use the scheduler config file at PATH'",
))).subcommand(SubCommand::with_name("server").arg(Arg::from_usage(
"--config <PATH> 'Use the server config file at PATH'",
)))
)
.subcommand(
SubCommand::with_name("scheduler")
.arg(Arg::from_usage("--config <PATH> 'Use the scheduler config file at PATH'"))
.arg(Arg::from_usage("--syslog <LEVEL> 'Log to the syslog with LEVEL'")
.possible_values(LOG_LEVELS))
)
.subcommand(
SubCommand::with_name("server")
.arg(Arg::from_usage("--config <PATH> 'Use the server config file at PATH'"))
.arg(Arg::from_usage("--syslog <LEVEL> 'Log to the syslog with LEVEL'")
.possible_values(LOG_LEVELS))
)
}
fn check_init_syslog<'a>(name: &str, matches: &ArgMatches<'a>) {
if matches.is_present("syslog") {
let level = value_t!(matches, "syslog", log::LevelFilter)
.unwrap_or_else(|e| e.exit());
drop(syslog::init(Facility::LOG_DAEMON, level, Some(name)));
}
}
fn parse() -> Result<Command> {
@ -211,6 +232,7 @@ fn parse() -> Result<Command> {
.value_of("config")
.expect("missing config in parsed subcommand"),
);
check_init_syslog("sccache-scheduler", &matches);
if let Some(config) = scheduler_config::from_path(config_path)? {
Command::Scheduler(config)
} else {
@ -223,6 +245,7 @@ fn parse() -> Result<Command> {
.value_of("config")
.expect("missing config in parsed subcommand"),
);
check_init_syslog("sccache-buildserver", &matches);
if let Some(config) = server_config::from_path(config_path)? {
Command::Server(config)
} else {