Crate notify

Crate notify 

Source
Expand description

§Notify

This crate provides an interface to the org.freedesktop.Notifications interface. It also implements a log:Logger controlled entirely through the environment that can optionally send log messages to the Desktop Environment via Notifications.

notify::notify will send a notification to the client, whereas notify::action will send a notification with a list of prospective actions, to which the function will return the action chosen by the user, if any.

To use as a logger, simply call notify::init to initialize notify as the program logger, after which simply use warn!, log!, etc as usual. Control over the messages and level is done via two environment variables:

  • RUST_LOG control messages output to the terminal, identical to how env_logger works.
  • NOTIFY controls notifications sent to the Desktop Environment. By default, logs with log::Level::Error will be both printed to the terminal, and displayed via a Notification. Notifications can be displayed entirely at runtime by setting NOTIFY=none.

A binary can be compiled from the repository, providing a means to notify the command line.

Enums§

Error
Errors for the NotifyLogger.
Urgency
The urgency level of a Notification. The Desktop Environment is free to interpret this as it wants. This should, therefore, be seen as a suggestion.

Statics§

LEVEL
The current log level, set by the RUST_LOG environment variable
PROMPT_LEVEL
The current level to which messages should be notified. By default, only errors cause prompts. This is controlled via the NOTIFY environment variable, and can be set to none to only log to the terminal.

Functions§

action
Send a Notification across the User Bus with a set of Actions. The selected Action, if the user choose one, is returned.
init
Initialize the NotifyLogger as the program’s Logger.
init_error
Initialize the NotifyLogger as the program’s Logger, but print to stderr instead of stdout. Note that this only applies to direct logging, notification call fallback still prints to stdout.
level_color
Get the color that should be used for particular log level.
level_name
Get the pretty name of a log level.
level_urgency
Get the recommended notification urgency for each level.
notify
Send a stateless Notification across the User Bus. If there is a failure sending the message, it will be sent to the terminal.
set_notifier
Set an optional Notifier function that is called instead of the notify() function defined here, such as to run the binary compiled by this crate in cases of SetUID, where we cannot communicate to the User Bus in this process.