-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.c
45 lines (36 loc) · 837 Bytes
/
log.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "log.h"
#include <stdarg.h>
#include <syslog.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#define MAXLINE 4096
void log_info(const char *fmt, ...)
{
va_list p;
static char buff[MAXLINE];
va_start(p, fmt);
vsnprintf(buff, sizeof(buff), fmt, p);
fprintf(stderr, "信息: %s\n", buff);
va_end(p);
va_start(p, fmt);
syslog(LOG_INFO, fmt, p);
va_end(p);
}
void log_error(const char *fmt, ...)
{
va_list p;
static char buff[MAXLINE];
size_t n;
int errnod;
errnod = errno;
va_start(p, fmt);
vsnprintf(buff, sizeof(buff), fmt, p);
n = strlen(buff);
snprintf(buff + n, sizeof(buff) - n, ": %s", strerror(errnod));
fprintf(stderr, "错误: %s\n", buff);
va_end(p);
va_start(p, fmt);
syslog(LOG_ERR, fmt, p);
va_end(p);
}