summaryrefslogtreecommitdiffstats
path: root/proxy/src/gp_debug.c
blob: 4a1a26c5d38d223c9ab7081419dd023a15650608 (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
58
59
/* Copyright (C) 2011 the GSS-PROXY contributors, see COPYING for license */

#include "config.h"
#include "gp_debug.h"
#include "gp_log.h"

/* global debug switch */
int gp_debug;

void gp_debug_enable(int level)
{
    if (level == 0) level = 1;
    gp_debug = level;
    GPDEBUG("Debug Enabled (level: %d)\n", level);
}

void gp_log_failure(gss_OID mech, uint32_t maj, uint32_t min)
{
    char buf[MAX_LOG_LINE];

    gp_fmt_status(mech, maj, min, buf, MAX_LOG_LINE);

    fprintf(stderr, "Failed with: %s\n", buf);
}

const char *gp_debug_timestamp(void)
{
    static __thread char buffer[24];
    static __thread time_t timestamp = 0;
    struct tm tm_info;
    time_t now;

    time(&now);
    if (now == timestamp) return buffer;

    gmtime_r(&now, &tm_info);
    strftime(buffer, 24, "[%Y/%m/%d %H:%M:%S]: ", &tm_info);
    timestamp = now;
    return buffer;
}

void gp_debug_printf(const char *format, ...)
{
    va_list varargs;
    va_start(varargs, format);
    vfprintf(stderr, format, varargs);
    va_end(varargs);
}

void gp_debug_time_printf(const char *format, ...)
{
    va_list varargs;

    fprintf(stderr, "%s", gp_debug_timestamp());

    va_start(varargs, format);
    vfprintf(stderr, format, varargs);
    va_end(varargs);
}