-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_lib.c
More file actions
76 lines (66 loc) · 1.78 KB
/
log_lib.c
File metadata and controls
76 lines (66 loc) · 1.78 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Author: vyouzhi <vyouzhi@163.com>
* http://www.xda.cn
*
* File: log_lib.c
* Create Date: 2011-10-10 09:37:15
*
*/
#include "log_lib.h"
void d_log(const char *logs){
openlog(LOGFILE, LOG_PID|LOG_CONS, LOG_LOCAL0);
syslog(LOG_ALERT,"info: %s\n", logs);
closelog();
}
/*
static void doLog(LogContext *pContext, const char *caption, \
const char *text, const int text_len, const bool bNeedSync)
{
time_t t;
struct tm tm;
int buff_len;
int result;
t = time(NULL);
localtime_r(&t, &tm);
if ((result=pthread_mutex_lock(&pContext->log_thread_lock)) != 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_lock fail, " \
"errno: %d, error info: %s", \
__LINE__, result, STRERROR(result));
}
if (text_len + 64 > LOG_BUFF_SIZE)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"log buff size: %d < log text length: %d ", \
__LINE__, LOG_BUFF_SIZE, text_len + 64);
pthread_mutex_unlock(&(pContext->log_thread_lock));
return;
}
if ((pContext->pcurrent_buff - pContext->log_buff) + text_len + 64 \
> LOG_BUFF_SIZE)
{
log_fsync(pContext, false);
}
buff_len = sprintf(pContext->pcurrent_buff, \
"[%04d-%02d-%02d %02d:%02d:%02d] %s - ", \
tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, \
tm.tm_hour, tm.tm_min, tm.tm_sec, caption);
pContext->pcurrent_buff += buff_len;
memcpy(pContext->pcurrent_buff, text, text_len);
pContext->pcurrent_buff += text_len;
*pContext->pcurrent_buff++ = '\n';
if (!pContext->log_to_cache || bNeedSync)
{
log_fsync(pContext, false);
}
if ((result=pthread_mutex_unlock(&(pContext->log_thread_lock))) != 0)
{
fprintf(stderr, "file: "__FILE__", line: %d, " \
"call pthread_mutex_unlock fail, " \
"errno: %d, error info: %s", \
__LINE__, result, STRERROR(result));
}
}
*/
/* vim: set ts=4 sw=4: */