从C ++程序

时间:2015-11-03 17:09:07

标签: c++11 journal

我有一些Python程序,我想将其转换为C ++ 11代码,作为学习语言的一种方式。目标平台是Debian,内核版本> = 4.2(即systemd)。

在Python中,我可以使用syslog module将调试/日志记录信息记录到系统日志中。 在C中,我可以#include <syslog.h>。但是,从this article我明白,对于当前的C ++实现,没有这样的实现(不再)。如果程序是一个服务(或守护进程?),这显然会自动发生,虽然我没有收集如何区分消息优先级。

我已经用Google搜索但无法真正找到问题的解决方案:如何从C ++ 11程序中向系统日志发送信息?

编辑:(抛出手并放弃;-))因为我的问题似乎没有本机解决方案而且我还处于学习C ++的起始阶段,我现在考虑使用 C iso C ++,因为C本身支持带有syslog.h的syslog。

2 个答案:

答案 0 :(得分:5)

您还可以通过func setDataWithContent(content: EmbeddedContent) { if let htmlString = content.text { do { let encodedData = htmlString.dataUsingEncoding(NSUTF8StringEncoding)! let attributedOptions : [String: AnyObject] = [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding, NSFontAttributeName: UIFont(name: "SourceSansPro-Regular", size:16)!, NSForegroundColorAttributeName: UIColor.redColor() ] let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) htmlTextLabel.attributedText = attributedString } catch { fatalError("Error: \(error)") } } } sd_journal_send(3) c函数将日志数据发送到journald。

http://0pointer.de/blog/projects/journal-submit.html提供了有关此主题的更多信息和示例。

答案 1 :(得分:0)

我会使用SysLogAppenderLog4Cplus。但问题和答案是基于意见等等