Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed default log file to ~/.odilia.log #151

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ thiserror = "1.0.37"
zbus.workspace = true
serde_plain.workspace = true
figment = "0.10.15"
xdg = "2.4.1"
14 changes: 9 additions & 5 deletions common/src/settings/log.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

use serde::{Deserialize, Serialize};
///structure used for all the configurable options related to logging
#[derive(Debug, Serialize, Deserialize)]
#[allow(clippy::module_name_repetitions)]
Expand All @@ -16,10 +16,14 @@ pub struct LogSettings {
}
impl Default for LogSettings {
fn default() -> Self {
Self {
level: "info".to_owned(),
logger: LoggingKind::File("/var/log/odilia.log".into()),
}
let xdg_dirs = xdg::BaseDirectories::with_prefix("odilia").expect(
"unable to find the odilia config directory according to the xdg dirs specification",
);
let log_path = xdg_dirs
.place_data_file("odilia.log")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.place_data_file("odilia.log")
.place_state_file("odilia.log")

.expect("unable to place log file");

Self { level: "info".to_owned(), logger: LoggingKind::File(log_path) }
}
}

Expand Down
4 changes: 2 additions & 2 deletions odilia/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ pub fn init(config: &ApplicationConfig) -> eyre::Result<()> {
//this requires boxing because the types returned by this match block would be incompatible otherwise, since we return different layers depending on what we get from the configuration. It is possible to do it otherwise, hopefully, but for now this and a forced dereference at the end would do
let output_layer = match &config.log.logger {
LoggingKind::File(path) => {
let file = std::fs::File::options()
let file = std::fs::File::options()
.create_new(true)
.write(true)
.open(path)
.with_context(|| {
format!("creating log file '{}'", path.display())
})?;
let fmt =
let fmt =
tracing_subscriber::fmt::layer().with_ansi(false).with_writer(file);
fmt.boxed()
}
Expand Down
Loading