Skip to content

Commit

Permalink
moved log directory to make it aw-qt compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare authored and johan-bjareholt committed Mar 25, 2020
1 parent d456981 commit 6024d7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 20 additions & 4 deletions aw-server/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn get_config_dir() -> Result<PathBuf, ()> {
let mut dir = appdirs::user_config_dir(Some("activitywatch"), None, false)?;
dir.push("aw-server-rust");
fs::create_dir_all(dir.clone()).expect("Unable to create config dir");
return Ok(dir);
Ok(dir)
}

#[cfg(target_os = "android")]
Expand All @@ -37,7 +37,7 @@ pub fn get_data_dir() -> Result<PathBuf, ()> {
let mut dir = appdirs::user_data_dir(Some("activitywatch"), None, false)?;
dir.push("aw-server-rust");
fs::create_dir_all(dir.clone()).expect("Unable to create data dir");
return Ok(dir);
Ok(dir)
}

#[cfg(target_os = "android")]
Expand All @@ -52,7 +52,23 @@ pub fn get_cache_dir() -> Result<PathBuf, ()> {
let mut dir = appdirs::user_cache_dir(Some("activitywatch"), None)?;
dir.push("aw-server-rust");
fs::create_dir_all(dir.clone()).expect("Unable to create cache dir");
return Ok(dir);
Ok(dir)
}

#[cfg(target_os = "android")]
{
panic!("not implemented on Android");
}
}

pub fn get_log_dir() -> Result<PathBuf, ()> {
#[cfg(not(target_os = "android"))]
{
let mut dir = appdirs::user_cache_dir(Some("activitywatch"), None)?;
dir.push("log");
dir.push("aw-server-rust");
fs::create_dir_all(dir.clone()).expect("Unable to create cache dir");
Ok(dir)
}

#[cfg(target_os = "android")]
Expand All @@ -67,7 +83,7 @@ pub fn db_path() -> PathBuf {
db_path.push("sqlite-testing.db");
#[cfg(not(debug_assertions))]
db_path.push("sqlite.db");
return db_path;
db_path
}

#[cfg(target_os = "android")]
Expand Down
4 changes: 2 additions & 2 deletions aw-server/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use crate::dirs;

pub fn setup_logger() -> Result<(), fern::InitError> {
let mut logfile_path: PathBuf =
dirs::get_cache_dir().expect("Unable to get cache dir to store logs in");
logfile_path.push("logs");
dirs::get_log_dir().expect("Unable to get log dir to store logs in");
fs::create_dir_all(logfile_path.clone()).expect("Unable to create folder for logs");
#[cfg(debug_assertions)]
{
Expand Down Expand Up @@ -36,6 +35,7 @@ pub fn setup_logger() -> Result<(), fern::InitError> {
fern::Dispatch::new()
// Set some Rocket messages to debug level
// TODO: Log more if run in development/testing mode
.level(log::LevelFilter::Info)
.level_for("rocket::rocket", log::LevelFilter::Warn)
.level_for("_", log::LevelFilter::Warn)
.format(move |out, message, record| {
Expand Down

0 comments on commit 6024d7d

Please sign in to comment.