Skip to content

Commit

Permalink
Added debug logging option.
Browse files Browse the repository at this point in the history
  • Loading branch information
apognu committed Apr 27, 2024
1 parent f988ed1 commit a6d71b5
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 18 deletions.
180 changes: 180 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ unic-langid = "^0.9"
zeroize = "^1.3"
uzers = "0.12"
rand = "0.8.5"
tracing-appender = "0.2.3"
tracing-subscriber = "0.3.18"
tracing = "0.1.40"

[profile.release]
lto = true
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Usage: tuigreet [OPTIONS]
Options:
-h, --help show this usage information
-v, --version print version information
-d, --debug [FILE] enable debug logging to the provided file, or to
/tmp/tuigreet.log
-c, --cmd COMMAND command to run
-s, --sessions DIRS colon-separated list of Wayland session paths
--session-wrapper 'CMD [ARGS]...'
Expand Down Expand Up @@ -53,9 +55,12 @@ Options:
command to run to reboot the system
--power-no-setsid
do not prefix power commands with setsid
--kb-[command|sessions|power] [1-12]
change the default F-key keybindings to access the
command, sessions and power menus.
--kb-command [1-12]
F-key to use to open the command menu
--kb-sessions [1-12]
F-key to use to open the sessions menu
--kb-power [1-12]
F-key to use to open the power menu
```

## Usage
Expand Down
4 changes: 4 additions & 0 deletions contrib/man/tuigreet-1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ tuigreet - A graphical console greeter for greetd
*-v, --version*
Print program version and exit.

*-d, --debug [FILE]*
Enables debug logging to the provided FILE path, or to /tmp/tuigreet.log if no
file is specified.

*-c, --cmd CMD*
Specify which command to run on successful authentication. This can be
overridden by manual selection within *tuigreet*.
Expand Down
20 changes: 19 additions & 1 deletion src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::{
},
};

const DEFAULT_LOG_FILE: &str = "/tmp/tuigreet.log";
const DEFAULT_LOCALE: Locale = Locale::en_US;
const DEFAULT_ASTERISKS_CHARS: &str = "*";
// `startx` wants an absolute path to the executable as a first argument.
Expand Down Expand Up @@ -91,6 +92,9 @@ impl SecretDisplay {

#[derive(SmartDefault)]
pub struct Greeter {
pub debug: bool,
pub logfile: String,

#[default(DEFAULT_LOCALE)]
pub locale: Locale,
pub config: Option<Matches>,
Expand Down Expand Up @@ -354,6 +358,7 @@ impl Greeter {

opts.optflag("h", "help", "show this usage information");
opts.optflag("v", "version", "print version information");
opts.optflagopt("d", "debug", "enable debug logging to the provided file, or to /tmp/tuigreet.log", "FILE");
opts.optopt("c", "cmd", "command to run", "COMMAND");
opts.optopt("s", "sessions", "colon-separated list of Wayland session paths", "DIRS");
opts.optopt("", "session-wrapper", "wrapper command to initialize the non-X11 session", "'CMD [ARGS]...'");
Expand Down Expand Up @@ -419,6 +424,15 @@ impl Greeter {
}
}

if self.config().opt_present("debug") {
self.debug = true;

self.logfile = match self.config().opt_str("debug") {
Some(file) => file.to_string(),
None => DEFAULT_LOG_FILE.to_string(),
}
}

if self.config().opt_present("issue") && self.config().opt_present("greeting") {
eprintln!("Only one of --issue and --greeting may be used at the same time");
print_usage(opts);
Expand Down Expand Up @@ -455,6 +469,8 @@ impl Greeter {
let max_uid = self.config().opt_str("user-menu-max-uid").and_then(|uid| uid.parse::<u16>().ok());
let (min_uid, max_uid) = get_min_max_uids(min_uid, max_uid);

tracing::info!("min/max UIDs are {}/{}", min_uid, max_uid);

if min_uid >= max_uid {
eprintln!("Minimum UID ({min_uid}) must be less than maximum UID ({max_uid})");
process::exit(1);
Expand All @@ -464,7 +480,9 @@ impl Greeter {
title: fl!("title_users"),
options: get_users(min_uid, max_uid),
selected: 0,
}
};

tracing::info!("found {} users", self.users.options.len());
}

if self.config().opt_present("remember-session") && self.config().opt_present("remember-user-session") {
Expand Down
2 changes: 2 additions & 0 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ pub fn get_sessions(greeter: &Greeter) -> Result<Vec<Session>, Box<dyn Error>> {

files.sort_by(|a, b| a.name.cmp(&b.name));

tracing::info!("found {} sessions", files.len());

Ok(files)
}

Expand Down
Loading

0 comments on commit a6d71b5

Please sign in to comment.