Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46e745e0 authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Gerrit Code Review
Browse files

Merge "Floss: Add log-output option for btmanagerd"

parents 32be2d35 21a07392
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ dbus-tokio = "0.7.3"
dbus-crossroads = "0.4.0"
dbus-crossroads = "0.4.0"
dbus_projection = { path = "../dbus_projection" }
dbus_projection = { path = "../dbus_projection" }
dbus_macros = { path = "../dbus_projection/dbus_macros" }
dbus_macros = { path = "../dbus_projection/dbus_macros" }
env_logger = "0.8.3"
futures = "0.3.13"
futures = "0.3.13"
inotify = "*"
inotify = "*"
log = "0.4.14"
log = "0.4.14"
+26 −14
Original line number Original line Diff line number Diff line
@@ -23,11 +23,27 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let matches = App::new("Bluetooth Manager")
    let matches = App::new("Bluetooth Manager")
        .arg(Arg::with_name("systemd").long("systemd").help("If btadapterd uses systemd init"))
        .arg(Arg::with_name("systemd").long("systemd").help("If btadapterd uses systemd init"))
        .arg(Arg::with_name("debug").long("debug").short("d").help("Enables debug level logs"))
        .arg(Arg::with_name("debug").long("debug").short("d").help("Enables debug level logs"))
        .arg(
            Arg::with_name("log-output")
                .long("log-output")
                .takes_value(true)
                .possible_values(&["syslog", "stderr"])
                .default_value("syslog")
                .help("Select log output"),
        )
        .get_matches();
        .get_matches();


    let is_debug = matches.is_present("debug");
    let is_debug = matches.is_present("debug");
    let is_systemd = matches.is_present("systemd");
    let is_systemd = matches.is_present("systemd");


    let level_filter = if is_debug { LevelFilter::Debug } else { LevelFilter::Info };

    let log_output = matches.value_of("log-output").unwrap_or("syslog");

    if log_output == "stderr" {
        env_logger::Builder::new().filter(None, level_filter).init();
    } else {
        // syslog is the default log output.
        let formatter = Formatter3164 {
        let formatter = Formatter3164 {
            facility: Facility::LOG_USER,
            facility: Facility::LOG_USER,
            hostname: None,
            hostname: None,
@@ -36,13 +52,9 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
        };
        };


        let logger = syslog::unix(formatter).expect("could not connect to syslog");
        let logger = syslog::unix(formatter).expect("could not connect to syslog");
    let _ = log::set_boxed_logger(Box::new(BasicLogger::new(logger))).map(|()| {
        let _ = log::set_boxed_logger(Box::new(BasicLogger::new(logger)))
        log::set_max_level(config_util::get_log_level().unwrap_or(if is_debug {
            .map(|()| log::set_max_level(config_util::get_log_level().unwrap_or(level_filter)));
            LevelFilter::Debug
    }
        } else {
            LevelFilter::Info
        }))
    });


    // Initialize config util
    // Initialize config util
    config_util::fix_config_file_format();
    config_util::fix_config_file_format();