summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-04-27 03:29:59 +0200
committerJokler <jokler.contact@gmail.com>2018-04-27 03:29:59 +0200
commit645bb1c2bfaecd1bca3da4b862ecffbd18bf3086 (patch)
tree54aa437017cb986b93675b5778dea53001af5cae /src
parent87120d35c1e2ee7eff52e9fd2d0a8458206a4cb6 (diff)
downloadfrippy-645bb1c2bfaecd1bca3da4b862ecffbd18bf3086.tar.gz
frippy-645bb1c2bfaecd1bca3da4b862ecffbd18bf3086.zip
Main: Replace the logger with log4rs
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs4
-rw-r--r--src/main.rs51
-rw-r--r--src/plugins/url.rs11
3 files changed, 19 insertions, 47 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 67a99d0..0e14e42 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -258,7 +258,9 @@ impl ThreadedPlugins {
.spawn(move || {
if let Err(e) = plugin.execute_threaded(&client, &message) {
log_error(e);
- };
+ } else {
+ debug!("{} sent response from thread", plugin.name());
+ }
})
.context(ErrorKind::ThreadSpawn)
{
diff --git a/src/main.rs b/src/main.rs
index 3660ccd..aae6035 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@
extern crate frippy;
extern crate glob;
extern crate irc;
+extern crate log4rs;
extern crate time;
#[cfg(feature = "mysql")]
@@ -21,7 +22,6 @@ extern crate failure;
#[macro_use]
extern crate log;
-use log::{Level, LevelFilter, Metadata, Record};
use std::collections::HashMap;
#[cfg(feature = "mysql")]
use std::sync::Arc;
@@ -44,58 +44,27 @@ use frippy::Config;
#[cfg(feature = "mysql")]
embed_migrations!();
-struct Logger;
-
-impl log::Log for Logger {
- fn enabled(&self, metadata: &Metadata) -> bool {
- metadata.target().contains("frippy")
- }
-
- fn log(&self, record: &Record) {
- if self.enabled(record.metadata()) {
- if record.metadata().level() >= Level::Debug {
- println!(
- "[{}]({}) {} -> {}",
- time::now().rfc822(),
- record.level(),
- record.target(),
- record.args()
- );
- } else {
- println!(
- "[{}]({}) {}",
- time::now().rfc822(),
- record.level(),
- record.args()
- );
- }
+fn main() {
+ if let Err(e) = log4rs::init_file("log.yml", Default::default()) {
+ use log4rs::Error;
+ match e {
+ Error::Log(e) => eprintln!("Log4rs error: {}", e),
+ Error::Log4rs(e) => eprintln!("Failed to parse \"log.yml\" as log4rs config: {}", e),
}
- }
- fn flush(&self) {}
-}
-
-static LOGGER: Logger = Logger;
+ return;
+ }
-fn main() {
// Print any errors that caused frippy to shut down
if let Err(e) = run() {
let text = e.causes()
.skip(1)
.fold(format!("{}", e), |acc, err| format!("{}: {}", acc, err));
error!("{}", text);
- };
+ }
}
fn run() -> Result<(), Error> {
- log::set_max_level(if cfg!(debug_assertions) {
- LevelFilter::Debug
- } else {
- LevelFilter::Info
- });
-
- log::set_logger(&LOGGER).unwrap();
-
// Load all toml files in the configs directory
let mut configs = Vec::new();
for toml in glob("configs/*.toml").unwrap() {
diff --git a/src/plugins/url.rs b/src/plugins/url.rs
index a54cabf..1ea6c9c 100644
--- a/src/plugins/url.rs
+++ b/src/plugins/url.rs
@@ -55,8 +55,7 @@ impl Title {
.and_then(|s| s.and_then(|s| s))
.ok_or(ErrorKind::MissingTitle)?;
- debug!("delimiters: {:?}", delimiters);
- debug!("title: {:?}", title);
+ debug!("Found title {:?} with delimiters {:?}", title, delimiters);
htmlescape::decode_html(title)
.map(|t| t.into())
@@ -132,7 +131,7 @@ impl UrlTitles {
} else {
og_title
}
- },
+ }
(Ok(title), _) => title,
(_, Ok(title)) => title,
(Err(e), _) => Err(e)?,
@@ -159,7 +158,7 @@ impl Plugin for UrlTitles {
}
fn execute_threaded(&self, client: &IrcClient, message: &Message) -> Result<(), FrippyError> {
- Ok(match message.command {
+ match message.command {
Command::PRIVMSG(_, ref content) => match self.url(content) {
Ok(title) => client
.send_privmsg(message.response_target().unwrap(), &title)
@@ -167,7 +166,9 @@ impl Plugin for UrlTitles {
Err(e) => Err(e).context(FrippyErrorKind::Url)?,
},
_ => (),
- })
+ }
+
+ Ok(())
}
fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), FrippyError> {