Skip to content

Commit

Permalink
Better logging on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
JCapucho committed Jun 17, 2020
1 parent 31a1e2d commit d119fc3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 56 deletions.
44 changes: 0 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ librespot = { version = "0.1.1", default-features = false, features = [
"with-tremor"
] }

[target."cfg(target_os = \"windows\")".dependencies]
windows-service = "0.2.0"

[target."cfg(unix)".dependencies]
daemonize = "0.4"
syslog = "4"
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ pub(crate) struct SpotifydConfig {
pub(crate) player_config: PlayerConfig,
pub(crate) session_config: SessionConfig,
pub(crate) onevent: Option<String>,
#[allow(unused)]
pub(crate) pid: Option<String>,
pub(crate) shell: String,
pub(crate) zeroconf_port: Option<u16>,
Expand Down
30 changes: 21 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,21 @@ fn setup_logger(log_target: LogTarget, log_level: LevelFilter) {
logger.chain(syslog::unix(log_format).expect("Couldn't initialize logger"))
}
#[cfg(target_os = "windows")]
LogTarget::Syslog => logger.chain(
std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(".spotifyd.log")
.expect("Couldn't initialize logger"),
),
LogTarget::Syslog => {
let dirs = directories::BaseDirs::new().unwrap();
let mut log_file = dirs.config_dir().to_path_buf();
log_file.push("spotifyd");
log_file.push(".spotifyd.log");

logger.chain(
std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(log_file)
.expect("Couldn't initialize logger"),
)
}
};

logger.apply().expect("Couldn't initialize logger");
Expand All @@ -72,7 +79,11 @@ fn main() {
}
#[cfg(target_os = "windows")]
{
LogTarget::Syslog
if std::env::var("SPOTIFYD_CHILD").is_ok() {
LogTarget::Syslog
} else {
LogTarget::Terminal
}
}
};
let log_level = if cli_config.verbose {
Expand Down Expand Up @@ -114,6 +125,7 @@ fn main() {

Command::new(std::env::current_exe().unwrap())
.args(args)
.env("SPOTIFYD_CHILD", "1")
.creation_flags(8 /* DETACHED_PROCESS */)
.spawn()
.expect("Couldn't spawn daemon");
Expand Down

0 comments on commit d119fc3

Please sign in to comment.