summaryrefslogtreecommitdiff
path: root/usr.sbin/ldapd/log.c
diff options
context:
space:
mode:
authorMartin Hedenfal <martinh@cvs.openbsd.org>2010-11-10 07:32:51 +0000
committerMartin Hedenfal <martinh@cvs.openbsd.org>2010-11-10 07:32:51 +0000
commit408354608ae943f836f74405593828f81d0bdf3b (patch)
treef3a379d84b53c929048db418fe2bdae792f7e680 /usr.sbin/ldapd/log.c
parentdd5782fa7760089f37d1a390e054de720cfa3fa1 (diff)
Prefix debug logging on stderr with time and pid, like syslog.
Diffstat (limited to 'usr.sbin/ldapd/log.c')
-rw-r--r--usr.sbin/ldapd/log.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/usr.sbin/ldapd/log.c b/usr.sbin/ldapd/log.c
index 4f27184409d..9560cfcead8 100644
--- a/usr.sbin/ldapd/log.c
+++ b/usr.sbin/ldapd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.1 2010/05/31 17:36:31 martinh Exp $ */
+/* $OpenBSD: log.c,v 1.2 2010/11/10 07:32:50 martinh Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <errno.h>
#include <netdb.h>
@@ -28,6 +29,7 @@
#include <string.h>
#include <syslog.h>
#include <time.h>
+#include <unistd.h>
#include "ldapd.h"
@@ -66,9 +68,22 @@ logit(int pri, const char *fmt, ...)
void
vlog(int pri, const char *fmt, va_list ap)
{
- char *nfmt;
+ char datebuf[24];
+ struct timeval tv;
+ struct tm *tm;
+ char *nfmt;
+ size_t rc;
+ time_t now;
if (debug) {
+ gettimeofday(&tv, NULL);
+ now = tv.tv_sec;
+ tm = localtime(&now);
+ rc = strftime(datebuf, sizeof(datebuf), "%b %e %H:%M:%S", tm);
+ if (rc == 0)
+ datebuf[0] = 0;
+ fprintf(stderr, "%s.%03li [%i] ", datebuf, tv.tv_usec / 1000, getpid());
+
/* best effort in out of mem situations */
if (asprintf(&nfmt, "%s\n", fmt) == -1) {
vfprintf(stderr, fmt, ap);