summaryrefslogtreecommitdiffstats
path: root/src/log.c
blob: d3f8d15b237f6fa5f1ea6c979bdafc2788e65ffc (plain)
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
#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);
    }
}