/*
 * Author:
 *         Kendy Kutzner <kutzner@ira.uka.de>
 *
 * (c) 2005 Research Group Dr. Fuhrmann, University of Karlsruhe, Germany
 * All rights reserved.
 *
 * $Id: debug.h,v 1.16 2005/12/29 16:21:58 kutzner Exp $
 *
 */

#ifndef _DEBUG_H_
#define _DEBUG_H_
#include <string>
using namespace std;

#include <stdarg.h>

class debug {
	public:
	debug();
	void conf(string c);
	void print(int facility, int priority, char * format, ...) __attribute__ (( format (printf, 4, 5))) ;

	void print(char * format, ...) __attribute__ (( format (printf, 2, 3)));
	enum facilities { DBG, DFLT, CBL, NODE, CONN, PARSE, MESG, CFG, ID, RAWMSG, BUF, FAC_COUNT}; // FAC_COUNT must be last item
	char * facilityname(facilities facility){
		switch (facility){
			case DFLT:   return "DFLT";
			case CBL:    return "CBL";
			case NODE:   return "NODE";
			case CONN:   return "CONN";
			case PARSE:  return "PARSE";
			case MESG:   return "MESG";
			case CFG:    return "CFG";
			case ID:     return "ID";
			case DBG:    return "DBG";
			case RAWMSG: return "RAWMSG";
			case BUF:    return "BUF";
			default:     return "--NEW FACILITY?--";
		}
	};
	/// Set the file descriptor where all debugging output is going to.
	void setfd(FILE*);
	private:
		int maxprio[FAC_COUNT];
		void do_print(int, int, char * format, va_list ap);
		/// The file descriptor where all debugging output is going to. Initializied by ctor to stderr.
		FILE * _fd;
};

// some ideas for priorities
// 0 really really very urgently important/critical
// 1 important/critical, programm will terminate
// 3 important, but normal
// 5 informational
// 6 debug
// 9 internal debugging, debug output may be dangerous

#ifndef _IN_MAIN_
extern debug dbg;
#else
debug dbg;
#endif


#endif

