2 * Copyright (c) 2015, 2016 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #include "syslog-libc.h"
25 #include "openvswitch/dynamic-string.h"
26 #include "socket-util.h"
27 #include "syslog-provider.h"
31 static void syslog_libc_open(struct syslogger
*this, int facility
);
32 static void syslog_libc_log(struct syslogger
*this, int pri
, const char *msg
);
34 static struct syslog_class syslog_libc_class
= {
40 struct syslogger parent
;
44 /* This function creates object that delegate all logging to libc's
45 * syslog implementation. */
47 syslog_libc_create(void)
49 struct syslog_libc
*this = xmalloc(sizeof *this);
51 this->parent
.class = &syslog_libc_class
;
52 this->parent
.prefix
= "<%B> %D{%h %e %T} %E %A:";
58 syslog_libc_open(struct syslogger
*this OVS_UNUSED
, int facility
)
62 /* openlog() is allowed to keep the pointer passed in, without making a
63 * copy. The daemonize code sometimes frees and replaces
64 * 'program_name', so make a private copy just for openlog(). (We keep
65 * a pointer to the private copy to suppress memory leak warnings in
66 * case openlog() does make its own copy.) */
67 ident
= nullable_xstrdup(program_name
);
69 openlog(ident
, LOG_NDELAY
, facility
);
73 syslog_libc_log(struct syslogger
*this OVS_UNUSED
, int pri
, const char *msg
)
75 syslog(pri
, "%s", msg
);