14

I keep getting very strange notifications which go away before I can read them, they are long, and appear at random times, the most recently one came up was during a kernel upgrade, it had a strange icon, and was long, but I didn't manage to read it because it was on the screen so briefly.

So I am wondering if there is any log which logs all calls to notify-send which logs the program calling it, and all the parameters given? Or if I can set up such a log to find out what these notifications are about? I am running Ubuntu GNOME 15.10 with GNOME 3.18.

5
  • 1
    As far as i know notify-send does not support a forced logging. I do have a really ugly workaround in mind which should be the last option/resort: Start a screen-recording and record as long as needed until the message appears. Stop the recording, start playback, jump to related section & pause. Using screenshots might as well be an option if you can trigger them fast enough (i.e. print-screen-key)
    – dufte
    May 10, 2016 at 11:22
  • @dufte: Is there not a way with aliases or something which would mean that a script is called instead of it which logs and then passes on the arguments to the real notify-send?
    – user364819
    May 10, 2016 at 11:25
  • askubuntu.com/questions/105566/… ?
    – DK Bose
    May 10, 2016 at 11:34
  • 1
    I would think that a simple python script that listens on DBus for the correct messages, and writes them to a log file, would do very well. Not that I'm offering to write one :-D
    – Jos
    May 10, 2016 at 11:37
  • If you are using Gnome, aren't they logged in then notifications menu?
    – Wilf
    May 10, 2016 at 12:26

1 Answer 1

15

Even didn't need a full script...
...but put it in the form of a script:

#!/bin/bash

file=$1

dbus-monitor "interface='org.freedesktop.Notifications'" |\
 grep --line-buffered "string" |\
 grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v |\
 grep --line-buffered '.*(?=string)|(?<=string).*' -oPi |\
 grep --line-buffered -v '^\s*$' |\
 xargs -I '{}' echo {} >> $file

To run it

  • Copy the "script" into an empty file, save it as keep_log.sh
  • Run it with the logfile as argument with the command

    /bin/bash /path/to/keep_log.sh /path/to/log.txt
    

The answer was retrieved from an earlier answer (not a dupe), in which this application of the method was mentioned as an example.

The answer I gave there, on its own turn, was based on this very nice answer, in which is explained that the method uses dbus-monitor to intercept the contents of notify-send. By editing the example there, we can make it write notify-send messages to a (log-) file.

Or, more elegant

...would be to add the date to the logfile, producing a logfile like:

---di 10 mei 2016 17:37:20 CEST---
SOme kind of a message!
---di 10 mei 2016 17:37:20 CEST---
The last message was misspelled so here i9s another one

In that case, the script would be:

#!/bin/bash

logfile=$1

dbus-monitor "interface='org.freedesktop.Notifications'" |\
grep --line-buffered "string" |\
grep --line-buffered -e method -e ":" -e '""' -e urgency -e notify -v |\
grep --line-buffered '.*(?=string)|(?<=string).*' -oPi |\
grep --line-buffered -v '^\s*$' |\
xargs -I '{}' \
printf "---$( date )---\n"{}"\n" >> $logfile
10
  • 1
    Wait, sorry, I'm not sure I fully understand, where is the log stored?
    – user364819
    May 10, 2016 at 12:27
  • 1
    @ParanoidPanda you can define your own path. I used /home/jacob/desktop/log.txt in my test. The file is created if it doesn't exist. May 10, 2016 at 12:29
  • 1
    Ok, I see now sender=:1.918 -> destination=:1.16 serial=7 path=/org/freedesktop/Notifications; ... etc., but how can I determine who is sending it?
    – vladkras
    Dec 11, 2017 at 11:26
  • 1
    I'm getting this sometimes: Error: xargs: unmatched double quote; by default quotes are special to xargs unless you use the -0 option
    – nealmcb
    Nov 5, 2018 at 14:06
  • 1
    @nealmcb see askubuntu.com/questions/842935/… Nov 5, 2018 at 14:14

You must log in to answer this question.