Openlog call before each syslog C ++

I created my own C library, which my employees intend to use. In this shell I intend to use syslogand depending on the input parameter, I want to switch between LOCAL0and LOCAL1.

The easiest way to find openlog()with LOCAL0or LOCAL1, depending on the input parameter, and then do syslog()`closelog ().

I have all 3 in one API (something similar below):

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()
}

My question is: can this API cause stress problems (performance issues)?

+4
source share
1 answer

This, in my opinion, is the wrong way, but the documentation is confused.

, , openlog C. . , syslog , openlog, , .

, , :

, , syslog() . ... priority OR- facility level ( ).

, , :

openlog() ; syslog(), , ident NULL.

openlog, - facility. , openlog ( ), OR priority syslog.

, - :

syslog(LOG_INFO | (flag?LOG_LOCAL1:LOG_LOCAL0),"%s",msg);
+4

Source: https://habr.com/ru/post/1542990/


All Articles