热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

是否有C的日志库?(比如log4jforC)-IsthereanyloglibraryforC?(likelog4jforC)

IvebeenworkinginJavaforalongtime,andIvebeenaccostumedtousethelog4jlibraryforlog

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.

我已经在Java工作了很长时间,我已经被认为使用log4j库来记录日志。这是一个很好的,现在我正在转向C我想找到一个类似的库,用于这种语言的日志。

3 个解决方案

#1


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的作者。

#2


3  

There is a log4c C library that mimics the log4j Java library. From the log4c documentation:

有一个log4c C库模仿log4j Java库。从log4c文档:

It is modeled after the Log for Java library staying as close to their API as is reasonable.

它是在Log for Java库保持尽可能接近其API的合理模型之后建模的。

#3


2  

Another option to consider is zf_log:

另一个需要考虑的选择是zf_log:

  • Debug logging is reduced to no-op in release builds (compiled out)
  • 在发布版本中,调试日志记录减少为无操作(已编译)
  • Arguments are not evaluated when the message is not logged
  • 未记录消息时不评估参数
  • No "unused" warning for variables used in log statements only
  • 仅对日志语句中使用的变量没有“未使用”警告
  • Log a memory region as HEX and ASCII
  • 将内存区域记录为HEX和ASCII
  • Optional built-in support for Android log and Apple system log (iOS, OS X)
  • 可选的内置支持Android日志和Apple系统日志(iOS,OS X)
  • Custom output functions (file, syslog, etc.)
  • 自定义输出功能(文件,系统日志等)

For example, that will output INFO log message:

例如,那将输出INFO日志消息:

ZF_LOGI("Number of arguments: %i", argc);

Which will look like:

看起来像是这样的:

04-29 22:43:20.244 40059  1299 I hello.MAIN main@hello.c:9 Number of arguments: 1

Exact representation is configurable and depends on build type (debug / release).

精确表示是可配置的,取决于构建类型(调试/发布)。


推荐阅读
  • 关于我们EMQ是一家全球领先的开源物联网基础设施软件供应商,服务新产业周期的IoT&5G、边缘计算与云计算市场,交付全球领先的开源物联网消息服务器和流处理数据 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 这是原文链接:sendingformdata许多情况下,我们使用表单发送数据到服务器。服务器处理数据并返回响应给用户。这看起来很简单,但是 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
  • 本文介绍了如何使用iptables添加非对称的NAT规则段,以实现内网穿透和端口转发的功能。通过查阅相关文章,得出了解决方案,即当匹配的端口在映射端口的区间内时,可以成功进行端口转发。详细的操作步骤和命令示例也在文章中给出。 ... [详细]
  • 本文介绍了计算机网络的定义和通信流程,包括客户端编译文件、二进制转换、三层路由设备等。同时,还介绍了计算机网络中常用的关键词,如MAC地址和IP地址。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • Linux如何安装Mongodb的详细步骤和注意事项
    本文介绍了Linux如何安装Mongodb的详细步骤和注意事项,同时介绍了Mongodb的特点和优势。Mongodb是一个开源的数据库,适用于各种规模的企业和各类应用程序。它具有灵活的数据模式和高性能的数据读写操作,能够提高企业的敏捷性和可扩展性。文章还提供了Mongodb的下载安装包地址。 ... [详细]
  • HSRP热备份路由器协议的应用及配置
    本文介绍了HSRP热备份路由器协议的应用及配置方法,包括设计目标、工作原理、配置命令等。通过HSRP协议,可以实现在主动路由器故障时自动切换到备份路由器,保证网络连通性。此外,还介绍了R1和R2路由器的配置方法以及Sw1和Sw2交换机的配置方法,最后还介绍了测试连通性和路由追踪的方法。 ... [详细]
author-avatar
迷茫的路人甲-
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有