diff --git a/snare.1 b/snare.1 index 1e0a5cd..ae7ea4f 100644 --- a/snare.1 +++ b/snare.1 @@ -43,8 +43,7 @@ This can be useful for debugging. .It Fl v enables more verbose logging. .Fl v -can be used up to 4 times, with each repetition increasing the quantity -of logging. +may be specified multiple times, with each increasing the quantity of logging. .El .Sh INTEGRATION WITH GITHUB .Nm diff --git a/src/httpserver.rs b/src/httpserver.rs index 6992207..282ee7f 100644 --- a/src/httpserver.rs +++ b/src/httpserver.rs @@ -185,11 +185,12 @@ fn request(snare: &Arc, mut stream: TcpStream) { } drop(conf); + let repo_id = format!("github/{}/{}", owner, repo); + snare.info(&format!("Received {event_type} for {repo_id}")); if event_type == "ping" { return; } - let repo_id = format!("github/{}/{}", owner, repo); let qj = QueueJob::new( repo_id, owner.to_owned(), diff --git a/src/main.rs b/src/main.rs index 71d14c9..ec91087 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,9 @@ use std::{ }; use getopts::Options; -use libc::{c_char, openlog, syslog, LOG_CONS, LOG_CRIT, LOG_DAEMON, LOG_ERR, LOG_WARNING}; +use libc::{ + c_char, openlog, syslog, LOG_CONS, LOG_CRIT, LOG_DAEMON, LOG_ERR, LOG_INFO, LOG_WARNING, +}; use nix::{ fcntl::OFlag, unistd::{daemon, pipe2, setresgid, setresuid, Gid, Uid}, @@ -45,6 +47,7 @@ const SNARE_CONF_PATH: &str = "/etc/snare/snare.conf"; pub enum LogLevel { Error, Warn, + Info, } pub(crate) struct Snare { @@ -100,6 +103,7 @@ impl Snare { let syslog_level = match self.log_level { LogLevel::Error => LOG_ERR, LogLevel::Warn => LOG_WARNING, + LogLevel::Info => LOG_INFO, }; unsafe { syslog(syslog_level, fmt.as_ptr(), msg.as_ptr()); @@ -126,6 +130,15 @@ impl Snare { pub fn warn(&self, msg: &str) { self.log(msg, LogLevel::Warn); } + + /// Log `msg` as an informational message. + /// + /// # Panics + /// + /// If `msg` contains a `NUL` byte. + pub fn info(&self, msg: &str) { + self.log(msg, LogLevel::Info); + } } /// Try to find a `snare.conf` file. @@ -239,7 +252,8 @@ pub fn main() { let log_level = match matches.opt_count("v") { 0 => LogLevel::Error, - _ => LogLevel::Warn, + 1 => LogLevel::Warn, + _ => LogLevel::Info, }; change_user(&conf);