【问题标题】:sd_journal_send to send binary data. How can I retrieve the data using journalctl?sd_journal_send 发送二进制数据。如何使用 journalctl 检索数据?
【发布时间】:2018-07-05 00:28:26
【问题描述】:

我将 systemd-journal 视为一种从外部处理器收集日志的方法。我对它在必要时收集二进制数据的能力非常感兴趣。

我现在只是在测试和调查期刊。我很清楚还有其他可能更好的解决方案。

我正在像这样记录二进制数据:

// strData is a string container containing binary data
strData += '\0';

sd_journal_send(
    "MESSAGE=test_msg",
    "MESSAGE_ID=12345",
    "BINARY=%s", strData.c_str(),
    NULL);

使用journalctl 工具时会显示日志行。我可以从终端找到这样的日志行:

journalctl MESSAGE_ID=12345

我可以像这样从终端获取日志中所有日志的二进制数据:

journalctl --field=BINARY

我需要将二进制数据保存到文件中,以便我可以从程序中访问并对其进行解码。我该怎么做?

这不起作用:

journalctl --field=BINARY MESSAGE_ID=12345

我到达那里错误:

“以'MESSAGE_ID=1234567890987654321”开头的无关参数

有什么建议吗? systemd-journal 上的文档似乎很薄。提前致谢。

【问题讨论】:

    标签: c++ linux binary systemd systemd-journald


    【解决方案1】:

    你选错了。请参阅文档:

       -F, --field=
           Print all possible data values the specified field can take in all entries of the journal.
    

       --output-fields=
           A comma separated list of the fields which should be included in the output. 
    

    您还必须指定纯输出格式 (-o cat) 才能获取原始内容:

    journalctl  --output-fields=BINARY  MESSAGE_ID=12345  -o cat
    

    【讨论】:

    • 我正在运行 16.04.4 的 Ubuntu,并且好像我已经安装了 systemd 229。 229 似乎不支持 --output-field。我现在正在寻找如何升级。
    猜你喜欢
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    • 2015-09-18
    • 2017-10-31
    • 1970-01-01
    相关资源
    最近更新 更多