notilog

package module
v0.0.0-...-99ab7b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: LGPL-3.0 Imports: 8 Imported by: 1

README

Notilog

This is a small daemon to log notifications.

NOTE: The implementation of the storage used by default is in-memory, so the daemon will lose all the backlog as soon as it is restarted.

It is meant to be used with a client.

Build

There is a make target.

make build

If you have problems with the dependencies, you might need to

export GOPRIVATE=git.sr.ht

Install

There is a simple makefile target install that assumes that you are on a archlinux-like distro. It builds and installs the daemon and cli to /usr/bin and a systemd unit to /usr/lib/systemd/user/notilogd.service.

To enable the unit

systemctl --user enable notilogd.service

Usage

Both the daemon and the cli read the configuration from 4 places, with the following order:

  • default values backed into the code
  • configuration file
  • environment variables
  • flags on the command line

The configuration file has a simple key=value structure, where the key is in snake_case. The corresponding environment variable is SCREAMING_SNAKE_CASE. The flags are in kebab-case.

The configuration is, by default, read from $XDG_CONFIG_DIR/notilog and is notilogd.conf for the daemon and notilog.conf for the cli.

The daemon has a somehow simple configuration space:

Usage of notilogd:
  -config string
        Path to the config file
  -json-logs
        Format logs as json
  -log-level string
        Set logger to the specified level
  -socket-path string
        Path to the control socket
  -sqlite-storage string
        Path to the sqlite db to save the notifications to (if this is set, this storage will be used in place of the in-memory one)

log-level may be any of (case insensitive) trace, debug, info, warning, error.

The cli has 4 subcommands:

Usage: notilogctl [globalOpts] SUBCMD

globalOpts:
        -config Path to the config file
        -log-level Set the log level
        -socket-path Path to the control socket

Subcmds:
        get
        prune
        restart
        stop
        help

Type notilogctl [SUBCMD] --help for more help

Use get to retrieve the logged notifications:

$ notilogctl get
notify-send | notification | one   | 2024-03-16T20:05:14+01:00
notify-send | notification | two   | 2024-03-16T20:05:17+01:00
notify-send | notification | three | 2024-03-16T20:05:20+01:00

You can limit the retrieved notifications with --tail <n>, filter by program with --program <prog-name> and by time interval since now with --since <duration> (the duration here follows golang parsing rules).

Use prune to empty the notification store, restart to restart the daemon and stop to make it exit.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformedMsg     = errors.New("malformed message")
	ErrNotANotification = errors.New("message is not a notification")
)

Functions

func TranslateHeaders

func TranslateHeaders(headerMap map[dbus.HeaderField]dbus.Variant) map[string]string

func ValidateCriterion

func ValidateCriterion(c Criterion) error

Types

type Action

type Action int
const (
	StopAction Action = iota
	RestartAction
)

type Criterion

type Criterion struct {
	Field Field
	Op    Operator
	Value any
}

func (Criterion) Eval

func (c Criterion) Eval(n *Notification) bool

type Field

type Field string
const (
	FieldProgram   Field = "program"
	FieldTitle     Field = "title"
	FieldBody      Field = "body"
	FieldSender    Field = "sender"
	FieldSerial    Field = "serial"
	FieldCreatedAt Field = "created_at"
)

type NotiListener

type NotiListener struct {
	// contains filtered or unexported fields
}

func NewNotiListener

func NewNotiListener(out chan *dbus.Message) (*NotiListener, error)

func (*NotiListener) Close

func (n *NotiListener) Close() error

func (*NotiListener) Run

type Notification

type Notification struct {
	Program   string    `json:"program"`
	Title     string    `json:"title"`
	Body      string    `json:"body"`
	Sender    string    `json:"sender"`
	Serial    uint32    `json:"serial"`
	CreatedAt time.Time `json:"created_at"`
}

func FromMessage

func FromMessage(msg *dbus.Message) (*Notification, error)

func (*Notification) GetField

func (n *Notification) GetField(field string) (string, bool)

func (*Notification) WithEscapedBody

func (n *Notification) WithEscapedBody() *Notification

type Operator

type Operator string
const (
	OperatorEq    Operator = "="
	OperatorNe    Operator = "!="
	OperatorIn    Operator = "in"
	OperatorNotIn Operator = "not in"
	OperatorGt    Operator = ">"
	OperatorGe    Operator = ">="
	OperatorLt    Operator = "<"
	OperatorLe    Operator = "<="
)

type Storage

type Storage interface {
	// Append is the insertion method.
	Append(context.Context, *Notification) error
	// Query gives access to the saved methods. The list of criteria are
	// meant as and-concatenated.
	Query(context.Context, ...Criterion) ([]*Notification, error)
	// Prune should erase all the notifications from the store.
	Prune(context.Context) error
}

Storage is append only and exposes a method to access the stored notifications, with optional filtering.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL