Browse Source

Add loglevel support with default of notice level, configurable on command line

master
Con Kolivas 11 years ago
parent
commit
c274457caa
  1. 11
      src/ckpool.c
  2. 40
      src/ckpool.h
  3. 48
      src/libckpool.h

11
src/ckpool.c

@ -303,7 +303,9 @@ int main(int argc, char **argv)
global_ckp = &ckp;
memset(&ckp, 0, sizeof(ckp));
while ((c = getopt(argc, argv, "c:n:s:")) != -1) {
ckp.loglevel = LOG_NOTICE;
while ((c = getopt(argc, argv, "c:n:s:l:")) != -1) {
switch (c) {
case 'c':
ckp.config = optarg;
@ -314,6 +316,13 @@ int main(int argc, char **argv)
case 's':
ckp.socket_dir = strdup(optarg);
break;
case 'l':
ckp.loglevel = atoi(optarg);
if (ckp.loglevel < LOG_EMERG || ckp.loglevel > LOG_DEBUG) {
quit(1, "Invalid loglevel (range %d - %d): %d",
LOG_EMERG, LOG_DEBUG, ckp.loglevel);
}
break;
}
}

40
src/ckpool.h

@ -65,4 +65,44 @@ struct ckpool_instance {
ckpool_t *global_ckp;
/* Placeholders for when we have more comprehensive logging facilities */
#define LOGMSG(_loglevel, fmt, ...) do { \
if (global_ckp->loglevel >= _loglevel && fmt) { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
if (_loglevel <= LOG_ERR) \
fprintf(stderr, " with errno %d: %s", errno, strerror(errno)); \
fflush(stderr); \
} \
} while (0)
#define LOGEMERG(fmt, ...) LOGMSG(LOG_EMERG, fmt, ##__VA_ARGS__)
#define LOGALERT(fmt, ...) LOGMSG(LOG_ALERT, fmt, ##__VA_ARGS__)
#define LOGCRIT(fmt, ...) LOGMSG(LOG_CRIT, fmt, ##__VA_ARGS__)
#define LOGERR(fmt, ...) LOGMSG(LOG_ERR, fmt, ##__VA_ARGS__)
#define LOGWARNING(fmt, ...) LOGMSG(LOG_WARNING, fmt, ##__VA_ARGS__)
#define LOGNOTICE(fmt, ...) LOGMSG(LOG_NOTICE, fmt, ##__VA_ARGS__)
#define LOGINFO(fmt, ...) LOGMSG(LOG_INFO, fmt, ##__VA_ARGS__)
#define LOGDEBUG(fmt, ...) LOGMSG(LOG_DEBUG, fmt, ##__VA_ARGS__)
#define IN_FMT_FFL " in %s %s():%d"
#define quitfrom(status, _file, _func, _line, fmt, ...) do { \
if (fmt) { \
fprintf(stderr, fmt IN_FMT_FFL, ##__VA_ARGS__, _file, _func, _line); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} \
exit(status); \
} while (0)
#define quit(status, fmt, ...) do { \
if (fmt) { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} \
exit(status); \
} while (0)
#endif /* CKPOOL_H */

48
src/libckpool.h

@ -173,54 +173,6 @@ static inline void flip_80(void *dest_p, const void *src_p)
#define LOG_DEBUG 7 /* debug-level messages */
#endif
/* Placeholders for when we have more comprehensive logging facilities */
#define LOGERR(fmt, ...) do { \
if (fmt) { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
if (errno)\
fprintf(stderr, " with errno %d:%s", errno, strerror(errno)); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} \
} while (0)
#define LOGMSG(fmt, ...) do { \
if (fmt) { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} \
} while (0)
#define LOGEMERG(fmt, ...) LOGMSG(fmt, ##__VA_ARGS__)
#define LOGALERT(fmt, ...) LOGMSG(fmt, ##__VA_ARGS__)
#define LOGCRIT(fmt, ...) LOGMSG(fmt, ##__VA_ARGS__)
#define LOGWARNING(fmt, ...) LOGMSG(fmt, ##__VA_ARGS__)
#define LOGNOTICE(fmt, ...) LOGMSG(fmt, ##__VA_ARGS__)
#define LOGINFO(fmt, ...) LOGMSG(fmt, ##__VA_ARGS__)
#define LOGDEBUG(fmt, ...) LOGMSG(fmt, ##__VA_ARGS__)
#define IN_FMT_FFL " in %s %s():%d"
#define quitfrom(status, _file, _func, _line, fmt, ...) do { \
if (fmt) { \
fprintf(stderr, fmt IN_FMT_FFL, ##__VA_ARGS__, _file, _func, _line); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} \
exit(status); \
} while (0)
#define quit(status, fmt, ...) do { \
if (fmt) { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
if (status || errno)\
fprintf(stderr, " with errno %d:%s", errno, strerror(errno)); \
fprintf(stderr, "\n"); \
fflush(stderr); \
} \
exit(status); \
} while (0)
#define PAGESIZE (4096)
/* ck locks, a write biased variant of rwlocks */

Loading…
Cancel
Save