Annotation of embedaddon/strongswan/src/libstrongswan/utils/debug.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2006 Martin Willi
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include <stdarg.h>
! 17:
! 18: #include "debug.h"
! 19:
! 20: ENUM(debug_names, DBG_DMN, DBG_ANY,
! 21: "DMN",
! 22: "MGR",
! 23: "IKE",
! 24: "CHD",
! 25: "JOB",
! 26: "CFG",
! 27: "KNL",
! 28: "NET",
! 29: "ASN",
! 30: "ENC",
! 31: "TNC",
! 32: "IMC",
! 33: "IMV",
! 34: "PTS",
! 35: "TLS",
! 36: "APP",
! 37: "ESP",
! 38: "LIB",
! 39: "ANY",
! 40: );
! 41:
! 42: ENUM(debug_lower_names, DBG_DMN, DBG_ANY,
! 43: "dmn",
! 44: "mgr",
! 45: "ike",
! 46: "chd",
! 47: "job",
! 48: "cfg",
! 49: "knl",
! 50: "net",
! 51: "asn",
! 52: "enc",
! 53: "tnc",
! 54: "imc",
! 55: "imv",
! 56: "pts",
! 57: "tls",
! 58: "app",
! 59: "esp",
! 60: "lib",
! 61: "any",
! 62: );
! 63:
! 64: /**
! 65: * level logged by the default logger
! 66: */
! 67: static level_t default_level = 1;
! 68:
! 69: /**
! 70: * stream logged to by the default logger
! 71: */
! 72: static FILE *default_stream = NULL;
! 73:
! 74: /**
! 75: * default dbg function which printf all to stderr
! 76: */
! 77: void dbg_default(debug_t group, level_t level, char *fmt, ...)
! 78: {
! 79: if (!default_stream)
! 80: {
! 81: default_stream = stderr;
! 82: }
! 83: if (level <= default_level)
! 84: {
! 85: va_list args;
! 86:
! 87: va_start(args, fmt);
! 88: vfprintf(default_stream, fmt, args);
! 89: fprintf(default_stream, "\n");
! 90: va_end(args);
! 91: }
! 92: }
! 93:
! 94: /**
! 95: * set the level logged by the default stderr logger
! 96: */
! 97: void dbg_default_set_level(level_t level)
! 98: {
! 99: default_level = level;
! 100: }
! 101:
! 102: /**
! 103: * set the stream logged by dbg_default() to
! 104: */
! 105: void dbg_default_set_stream(FILE *stream)
! 106: {
! 107: default_stream = stream;
! 108: }
! 109:
! 110: /**
! 111: * The registered debug hook.
! 112: */
! 113: void (*dbg) (debug_t group, level_t level, char *fmt, ...) = dbg_default;
! 114:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>