logging improvements

pull/353/merge
Richard Fuchs 8 years ago
parent 5e3ce30272
commit 4313cb2596

@ -25,7 +25,7 @@ LDFLAGS+= `mysql_config --libs`
include ../lib/lib.Makefile
SRCS= epoll.c garbage.c inotify.c main.c metafile.c stream.c recaux.c packet.c \
decoder.c output.c mix.c resample.c db.c
decoder.c output.c mix.c resample.c db.c log.c
LIBSRCS= loglib.c auxlib.c rtplib.c
OBJS= $(SRCS:.c=.o) $(LIBSRCS:.c=.o)

@ -56,7 +56,7 @@ static int check_conn() {
if (!c_mysql_host || !c_mysql_db)
return -1;
ilog(LOG_DEBUG, "connecting to MySQL");
dbg("connecting to MySQL");
mysql_conn = mysql_init(NULL);
if (!mysql_conn)
@ -93,7 +93,7 @@ static int check_conn() {
"(?,?,?)"))
goto err;
ilog(LOG_DEBUG, "Connection to MySQL established");
dbg("Connection to MySQL established");
return 0;

@ -0,0 +1,28 @@
#include "log.h"
#include <syslog.h>
#include <stdarg.h>
#include <stdio.h>
#include "loglib.h"
__thread const char *log_info_call, *log_info_stream;
__thread unsigned long log_info_ssrc;
void __ilog(int prio, const char *fmt, ...) {
va_list ap;
char prefix[300] = "";
char *pp = prefix;
char *endp = prefix + sizeof(prefix);
if (log_info_call)
pp += snprintf(pp, endp - pp, "[C %s] ", log_info_call);
if (log_info_stream)
pp += snprintf(pp, endp - pp, "[S %s] ", log_info_stream);
if (log_info_ssrc)
pp += snprintf(pp, endp - pp, "[0x%lx] ", log_info_ssrc);
va_start(ap, fmt);
__vpilog(prio, prefix, fmt, ap);
va_end(ap);
}

@ -8,7 +8,11 @@
#include <string.h>
#include <stdlib.h>
#define __ilog(...) __ilog_np(__VA_ARGS__)
#define dbg(fmt, ...) ilog(LOG_DEBUG, fmt, ##__VA_ARGS__)
void __ilog(int prio, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
extern __thread const char *log_info_call, *log_info_stream;
extern __thread unsigned long log_info_ssrc;
#endif

@ -230,10 +230,12 @@ void packet_process(stream_t *stream, unsigned char *buf, unsigned len) {
goto err;
packet->seq = ntohs(packet->rtp->seq_num);
unsigned long ssrc_num = ntohl(packet->rtp->ssrc);
log_info_ssrc = ssrc_num;
dbg("packet parsed successfully, seq %u", packet->seq);
// insert into ssrc queue
ssrc_t *ssrc = ssrc_get(stream, ntohl(packet->rtp->ssrc));
ssrc_t *ssrc = ssrc_get(stream, ssrc_num);
// check seq for dupes
if (G_UNLIKELY(ssrc->seq == -1)) {
@ -255,15 +257,18 @@ seq_ok:
// got a new packet, run the decoder
ssrc_run(ssrc);
log_info_ssrc = 0;
return;
dupe:
dbg("skipping dupe packet (new seq %i prev seq %i)", packet->seq, ssrc->seq);
pthread_mutex_unlock(&ssrc->lock);
log_info_ssrc = 0;
return;
err:
ilog(LOG_WARN, "Failed to parse packet headers");
ignore:
packet_free(packet);
log_info_ssrc = 0;
}

@ -40,6 +40,9 @@ static void stream_handler(handler_t *handler) {
stream_t *stream = handler->ptr;
unsigned char *buf = NULL;
log_info_call = stream->metafile->name;
log_info_stream = stream->name;
//dbg("poll event for %s", stream->name);
pthread_mutex_lock(&stream->lock);
@ -63,11 +66,15 @@ static void stream_handler(handler_t *handler) {
// got a packet
pthread_mutex_unlock(&stream->lock);
packet_process(stream, buf, ret);
log_info_call = NULL;
log_info_stream = NULL;
return;
out:
pthread_mutex_unlock(&stream->lock);
free(buf);
log_info_call = NULL;
log_info_stream = NULL;
}

Loading…
Cancel
Save