如何记录所有通知发送操作?

10 notification log notify-send

我不断收到非常奇怪的通知,在我阅读它们之前就消失了,它们很长,并且随机出现,最近出现的是在内核升级期间,它有一个奇怪的图标,而且很长,但我没有无法阅读它,因为它在屏幕上如此短暂。

所以我想知道是否有任何日志将所有调用notify-send记录到调用它的程序中,以及所有给定的参数?或者我是否可以设置这样的日志来找出这些通知的内容?我正在使用 GNOME 3.18 运行 Ubuntu GNOME 15.10。

Jac*_*ijm 9

甚至不需要一个完整的脚本......
但把它放在脚本的形式:

#!/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
Run Code Online (Sandbox Code Playgroud)

运行它

  • 将“脚本”复制到一个空文件中,另存为 keep_log.sh
  • 使用日志文件作为参数与命令运行它

    /bin/bash /path/to/keep_log.sh /path/to/log.txt
    
    Run Code Online (Sandbox Code Playgroud)

答案是从较早的答案(不是欺骗)中检索到的,其中提到了该方法的这种应用作为示例。

我在那里给出的答案本身就是基于这个非常好的答案,其中解释了该方法用于dbus-monitor拦截通知发送的内容。通过在那里编辑示例,我们可以使其将notify-send消息写入(log-) 文件。

或者,更优雅

...将日期添加到日志文件,生成一个日志文件,如:

/bin/bash /path/to/keep_log.sh /path/to/log.txt
Run Code Online (Sandbox Code Playgroud)

在这种情况下,脚本将是:

---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
Run Code Online (Sandbox Code Playgroud)