Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
mxq
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
3
Code
Issues
21
Pull requests
3
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
0951952
helper
manpages
mysql
web
.gitignore
.vimrc
Doxyfile
LICENSE
Makefile
README.md
keywordset.c
keywordset.h
mx_flock.c
mx_flock.h
mx_getopt.c
mx_getopt.h
mx_log.c
mx_log.h
mx_mysql.c
mx_mysql.h
mx_proc.c
mx_proc.h
mx_util.c
mx_util.h
mxq.h
mxq_daemon.c
mxq_daemon.h
mxq_group.c
mxq_group.h
mxq_job.c
mxq_job.h
mxq_log.c
mxqadmin.c
mxqd.c
mxqd.h
mxqd_control.c
mxqd_control.h
mxqdctl-hostconfig.sh
mxqdump.c
mxqkill.c
mxqps.c
mxqset.c
mxqsub.c
os-release
parser.y
ppidcache.c
ppidcache.h
test_keywordset.c
test_mx_log.c
test_mx_mysql.c
test_mx_util.c
test_mxqd_control.c
test_parser.c
xmalloc.h
Breadcrumbs
mxq
/
mx_log.c
Blame
Blame
Latest commit
History
History
190 lines (147 loc) · 3.78 KB
Breadcrumbs
mxq
/
mx_log.c
Top
File metadata and controls
Code
Blame
190 lines (147 loc) · 3.78 KB
Raw
#define _GNU_SOURCE #include <stdio.h> #include <stdarg.h> #include <errno.h> #include "mx_log.h" #define MX_LOG_GET (MX_LOG_NONE-1) int mx_log_errno = 0; int mx_log_level_set(int level) { static int loglevel = MX_LOG_WARNING; int oldloglevel = loglevel; switch (level) { case MX_LOG_GET: return loglevel; case MX_LOG_NONE: case MX_LOG_EMERG: case MX_LOG_ALERT: case MX_LOG_CRIT: case MX_LOG_ERR: case MX_LOG_WARNING: case MX_LOG_NOTICE: case MX_LOG_INFO: case MX_LOG_DEBUG: loglevel=level; return oldloglevel; } return -(mx_log_errno=EINVAL); } int mx_log_level_mxlog_to_syslog(int level) { level = MX_LOG_MXLOG_TO_SYSLOG(level); if (level < LOG_EMERG || level > LOG_DEBUG) return -(mx_log_errno=EINVAL); return level; } int mx_log_level_syslog_to_mxlog(int level) { if (level < LOG_EMERG || level > LOG_DEBUG) return -(mx_log_errno=EINVAL); level = MX_LOG_SYSLOG_TO_MXLOG(level); return level; } int mx_log_level_get(void) { return mx_log_level_set(MX_LOG_GET); } int mx_log_printf(const char *fmt, ...) { int len; int len2; char *msg = NULL; va_list ap; va_start(ap, fmt); len = vasprintf(&msg, fmt, ap); va_end(ap); if (len == -1) return -(mx_log_errno=ENOMEM); if (mx_log_print) return mx_log_print(msg, len); if (len == 0) { mx_free_null(msg); return 0; } len2 = fprintf(stderr, "%s\n", msg); fflush(stderr); mx_free_null(msg); if (len2 != len+1) return -(errno=EIO); return len; } static int log_log(int level, int loglevel, char *file, unsigned long line, const char *func, const char *msg) { char *prefix = ""; if (*msg == 0) return 0; switch (level) { case MX_LOG_EMERG: prefix = "EMERGENCY: "; break; case MX_LOG_ALERT: prefix = "ALERT: "; break; case MX_LOG_CRIT: prefix = "CRITCAL ERROR: "; break; case MX_LOG_ERR: prefix = "ERROR: "; break; case MX_LOG_WARNING: prefix = "WARNING: "; break; case MX_LOG_NOTICE: case MX_LOG_INFO: prefix = ""; break; case MX_LOG_DEBUG: prefix = "DEBUG: "; break; default: return -(mx_log_errno=EINVAL); } if (loglevel >= MX_LOG_DEBUG) return mx_log_printf("%s %s:%lu:%s(): %s%s", program_invocation_short_name, file, line, func, prefix, msg); return mx_log_printf("%s%s", prefix, msg); } int mx_logva_do(int level, char *file, unsigned long line, const char *func, const char *fmt, va_list ap) { int loglevel; int len; char *msg = NULL; int res; int preserved_errno = errno; loglevel = mx_log_level_get(); if (level > loglevel) { errno = preserved_errno; return 0; } len = vasprintf(&msg, fmt, ap); if (len == -1) { errno = preserved_errno; return -(mx_log_errno=ENOMEM); } if (mx_log_log) res = mx_log_log(level, loglevel, file, line, func, msg); else res = log_log(level, loglevel, file, line, func, msg); mx_free_null(msg); errno = preserved_errno; return res; } int mx_log_do(int level, char *file, unsigned long line, const char *func, const char *fmt, ...) { va_list ap; int res; va_start(ap, fmt); res = mx_logva_do(level, file, line, func, fmt, ap); va_end(ap); return res; } int mx_log_finish(void) { if (mx_log_log) mx_log_log(MX_LOG_NONE, MX_LOG_NONE, NULL, 0, NULL, NULL); if (mx_log_print) mx_log_print(NULL, 0); return 0; }
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
You can’t perform that action at this time.