summaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
authorDavid Troy <dave@popvox.com>2006-04-08 02:59:37 +0000
committerDavid Troy <dave@popvox.com>2006-04-08 02:59:37 +0000
commitab4b54852ac9270880a85acc18a3718fd93e2de2 (patch)
tree4faa4f0b79a6e642849b5f3344beff4304e41b63 /src/log.c
parenta6bb95888b0262222975589d8c651798c1f1c773 (diff)
parentedf54a3c22f04b10a0ff8694cf03ed81fd7079c0 (diff)
downloadastmanproxy-ab4b54852ac9270880a85acc18a3718fd93e2de2.tar.gz
astmanproxy-ab4b54852ac9270880a85acc18a3718fd93e2de2.tar.xz
astmanproxy-ab4b54852ac9270880a85acc18a3718fd93e2de2.zip
Trunk, based on 1.20
git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/trunk@101 f02b47b9-160a-0410-81a6-dc3441afb0ec
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/log.c b/src/log.c
new file mode 100644
index 0000000..d3f8d15
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,57 @@
+#include "astmanproxy.h"
+
+#define DATEFORMAT "%b %e %T"
+
+extern FILE *proxylog;
+extern int debug;
+extern pthread_mutex_t loglock;
+extern pthread_mutex_t debuglock;
+
+void debugmsg (const char *fmt, ...)
+{
+ va_list ap;
+
+ time_t t;
+ struct tm tm;
+ char date[80];
+
+ if (!debug)
+ return;
+
+ time(&t);
+ localtime_r(&t, &tm);
+ strftime(date, sizeof(date), DATEFORMAT, &tm);
+
+ pthread_mutex_lock(&debuglock);
+ va_start(ap, fmt);
+ printf("%s: ", date);
+ vprintf(fmt, ap);
+ printf("\n");
+ va_end(ap);
+ pthread_mutex_unlock(&debuglock);
+}
+
+
+void logmsg (const char *fmt, ...)
+{
+ va_list ap;
+
+ time_t t;
+ struct tm tm;
+ char date[80];
+
+ time(&t);
+ localtime_r(&t, &tm);
+ strftime(date, sizeof(date), DATEFORMAT, &tm);
+
+ if (proxylog) {
+ pthread_mutex_lock(&loglock);
+ va_start(ap, fmt);
+ fprintf(proxylog, "%s: ", date);
+ vfprintf(proxylog, fmt, ap);
+ fprintf(proxylog, "\n");
+ va_end(ap);
+ fflush(proxylog);
+ pthread_mutex_unlock(&loglock);
+ }
+}