有C的任何日志库吗? (如C的log4j) [英] Is there any log library for C? (like log4j for C)

查看:278
本文介绍了有C的任何日志库吗? (如C的log4j)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Java中工作了很长时间了,并且我不得不使用log4j库来记录日志.太好了,现在我要使用C语言,我想看看是否有类似的库可以记录这种语言的日志.

解决方案

到目前为止,我知道以下用于记录的库:log4c,sclog4c,syslog,zlog.

log4c

log4c 被发明为C语言的Log4J.如果您要查找类似于Log4J的东西"是因为您希望它类似于"Log4J",那么这很可能就是您想要的.正在寻找.

链接

sclog4c

sclog4c的发明与java.util.logging的最常用功能一样简单-尽可能简单.如果您要查找像Log4J之类的东西"是因为您希望它尽可能地小而简单,那么这很可能就是您想要的.

链接

syslog

syslog最初由Eric Allman作为sendmail的一部分开发,并已成为POSIX环境中守护程序/服务器日志记录的事实上的标准.它是基于客户端服务器的,通常希望记录某些内容的守护程序会将记录数据发送到syslogd,该记录在UDP端口514上进行侦听. 如果您确实要登录守护程序"或服务器,而专门寻找"Log4J之类的东西",那么这很可能就是您想要的.

链接

zlog

根据其描述,发明了一个类似于log4c的产品,同时又更小,更灵活.

链接

其他

力量与精益

由于C链接,思考和工作的方式不同,因此我不会寻找一般情况下功能强大的日志记录框架-与Java不同.如果您要使用功能完善的桌面应用程序"及其他功能,那么使用Java等强大的框架进行日志记录无疑是一个不错的选择.如果您正在实施命令行工具或类似工具,我敢打赌 一个精益的框架会更好-为什么只为记录日志而依赖lib2xml ...

速度

以防速度加快.不会因为某些原因而浪费周期对您很重要,请寻找一个日志记录框架,该框架在评估其他参数之前使用宏来评估日志级别.

缺点是您不能使用带有副作用的参数来调用日志例程.但这无论如何都不应该是一个用例.如果log语句由于包含副作用而不能被忽略,那将是惊人的.

好处是,在这样的框架中,日志语句增加了很少的周期,以至于它们几乎不存在-只是对全局,检查和条件分支的访问,跳过了其余的日志代码-2条指令,在当今许多CPU上,最好的情况是1个周期.

免责声明

我是sclog4c的作者.

I've been working in Java for a long time, and I've been accostumed to use the log4j library for logs. It's a wonderful, and now that I'm moving to C I'd like to find if there is a similar library for logs in this language.

解决方案

So far I know of the following libraries for logging: 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.

Links

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.

Links

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.

Links

zlog

This one was invented to be like log4c, just - according to its description - smaller and more flexible at the same time.

Links

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...

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.

Disclaimer

I am the author of sclog4c.

这篇关于有C的任何日志库吗? (如C的log4j)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆