11
So far I know of the following libraries for logging: log4c, sclog4c, syslog, zlog.
到目前为止,我知道以下用于日志记录的库:log4c,sclog4c,syslog,zlog。
log4c
log4c was invented to be a Log4J for C. If you're specifically looking for "something like Log4J" because you want it to be like "Log4J", this is most likely what you're looking for.
log4c被发明为C的Log4J。如果你特别想找“像Log4J这样的东西”,因为你希望它像“Log4J”,这很可能是你正在寻找的东西。
Links
- http://log4c.sourceforge.net/
- http://log4c.sourceforge.net/
sclog4c
sclog4c was invented to be as simple as the most frequently used features of java.util.logging
- as simple as possible. If you're looking for "something like Log4J" because you want it to be as small and simple as possible, this is most likely what you're looking for.
sclog4c被发明为与java.util.logging最常用的功能一样简单 - 尽可能简单。如果您正在寻找“像Log4J这样的东西”,因为您希望它尽可能小而简单,这很可能是您正在寻找的东西。
Links
- https://github.com/christianhujer/sclog4c
- https://github.com/christianhujer/sclog4c
syslog
syslog was originally developed by Eric Allman as part of sendmail and has become the defacto standard for daemon / server logging in POSIX environments. It is client-server based, usually the daemon that wants something to be logged will send the log data to a syslogd listening on UDP port 514. If you're specifically looking for "something like Log4J" because you actually want to log a daemon or server, this is most likely what you're looking for.
syslog最初由Eric Allman开发,是sendmail的一部分,已成为POSIX环境中守护程序/服务器日志记录的事实标准。它是基于客户端服务器的,通常需要记录某些内容的守护程序会将日志数据发送到在UDP端口514上侦听的syslogd。如果您特意查找“Log4J之类的东西”,因为您实际上想要记录守护程序或服务器,这很可能是你正在寻找的。
Links
- http://tools.ietf.org/html/rfc5424
- http://tools.ietf.org/html/rfc5424
- http://man7.org/linux/man-pages/man3/syslog.3.html
- http://man7.org/linux/man-pages/man3/syslog.3.html
- http://en.wikipedia.org/wiki/Syslog
- http://en.wikipedia.org/wiki/Syslog
zlog
This one was invented to be like log4c, just - according to its description - smaller and more flexible at the same time.
这个被发明成像log4c,只是 - 根据它的描述 - 同时更小,更灵活。
Links
- https://github.com/HardySimpson/zlog
- https://github.com/HardySimpson/zlog
Miscellaneous
Power vs. Lean
Because of the different way how C links, thinks and works, I would not look for a logging framework which is powerful in a general case - unlike in Java. If you're going for "full-blown desktop applications" and beyond, logging with powerful frameworks like in Java is certainly a good way to go. If you're implementing command line tools or similar, I bet that a lean framework is better - why would you want to depend on lib2xml just for the sake of logging...
由于C链接,思考和工作的方式不同,我不会寻找一般情况下强大的日志框架 - 与Java不同。如果您要使用“完整的桌面应用程序”以及更高版本,使用Java等强大的框架进行日志记录肯定是一个很好的方法。如果您正在实现命令行工具或类似工具,我敢打赌精益框架更好 - 为什么您只想为了记录而依赖lib2xml ...
Speed
In case speed resp. not wasting cycles matters to you for some reason, look for a logging framework which uses macros to evaluate the log level before the other arguments are evaluated.
如果速度相应。由于某种原因,不浪费周期对你很重要,寻找一个日志框架,它在评估其他参数之前使用宏来评估日志级别。
The downside is that you cannot call a log routine with arguments that have side-effects. But this shouldn't be a use case anyway. It would be astonishing if log statements were not ignorable because of containing side-effects.
缺点是您无法使用具有副作用的参数调用日志例程。但无论如何,这不应该是一个用例。如果因为包含副作用而无法忽略日志语句,那将是惊人的。
The upside is that log statements in such a framework add so few cycles that they're almost not there - just an access to a global, a check and a conditional branch, skipping the rest of the log code - 2 instructions, 1 cycle in the best case on many of today's CPUs.
好处是这样一个框架中的日志语句添加了很少的循环,它们几乎不存在 - 只是访问全局,检查和条件分支,跳过其余的日志代码 - 2条指令,1个循环当今许多CPU的最佳案例。
Disclaimer
I am the author of sclog4c.
我是sclog4c的作者。