- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经创建了我自己的 C 库,我的同事打算使用它。在这个包装器中,我打算使用 syslog
并根据输入参数,我希望在 LOCAL0
和 LOCAL1
之间切换。
我发现最简单的方法是使用 LOCAL0
或 LOCAL1
执行 openlog()
,具体取决于输入参数,然后执行 syslog()
和 `closelog()。
我在同一个包装器 API 中拥有所有 3 个(类似于下面的内容):
void syslog_wrap_api(int flag, const char *msg)
{
setlogmask(LOG_UPTO (LOG_INFO));
if(flag == 0)
openlog("myapplog",LOG_NDELAY,LOG_LOCAL0);
else
openlog("myapplog",LOG_NDELAY,LOG_LOCAL1);
syslog(LOG_INFO,"%s",msg);
closelog()
}
我的问题是,此 API 是否会在压力下导致问题(性能问题)?
最佳答案
在我看来,这是错误的做法,但文档令人困惑。
您是否在压力下遇到问题将取决于您的 C 库中 openlog
的实现。这很可能是有问题的。更重要的是,在多线程环境中,一个线程可能会在另一个线程发出 openlog
之后发出 syslog
,这意味着使用了错误的优先级。
如何正确执行此操作的关键在手册页中:
The facility argument establishes a default to be used if none is specified in subsequent calls to
syslog()
. Values for option and facility are given below ... Thepriority
argument is formed by OR-ing thefacility
and thelevel
values (explained below).
关于如何利用它的线索在这里:
The use of
openlog()
is optional; it will automatically be called bysyslog()
if necessary, in which caseident
will default toNULL
.
如果您不使用openlog
,则必须有某种方式来表达facility
。答案是您可以将设施指定为零到 openlog
(或根本不使用它),或者在设施中指定 syslog 的
。priority
参数
所以,像这样:
syslog(LOG_INFO | (flag?LOG_LOCAL1:LOG_LOCAL0),"%s",msg);
关于c++ - 在每个系统日志 C++ 之前调用 openlog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24005666/
我正在评估在我的 XPage 应用程序中使用 Openlog Logger [ https://www.openntf.org/main.nsf/project.xsp?r=project/XPage
我已经创建了我自己的 C 库,我的同事打算使用它。在这个包装器中,我打算使用 syslog 并根据输入参数,我希望在 LOCAL0 和 LOCAL1 之间切换。 我发现最简单的方法是使用 LOCAL0
在应用程序中,我想包含 OpenLog,但我对实现有一些疑问。 if (db.isOpen()){ //perform action }else{ OpenLogUtil.logError(s
我正在尝试使用 syslog() 并且通读手册页告诉我在 openlog() 中,“facility 参数建立了一个默认值,如果在随后调用 syslog() 时未指定任何内容” 据我了解,方法是: 1
我已经找了一段时间了,还没有找到明确的答案。到目前为止我发现的唯一链接是 here . 最佳答案 根据POSIX Specification syslog()、openlog() 和 closelog
今天早些时候,我通过 OpenLogic 提供的图像在 Azure 中全新安装了 CentOS。 当我尝试使用“yum update”更新系统时,我得到了 Loaded plugins: securi
我有一个c程序代码是 setlogmask (LOG_UPTO (LOG_NOTICE)); openlog ("thelog", LOG_CONS | LOG_PID | LOG_NDELAY,
将 Azure Openlogic CentOS 6.7 升级到 CentOS7.2 以使其具有类似于 CentOS 7.2 镜像的最佳方法是什么。 我做了 sudo yum update 但它没有升
我是一名优秀的程序员,十分优秀!