#ifndef LOG_H
#define LOG_H

/*
 * @(#)Log.h
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 1999-2002 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDWserver.cpp for details.
 *
 * Jörg Haeger, 27.05.1999
 */

#include <pthread.h>
#include <stdio.h>

/**
 * A Logging System
 *
 * @version 20021101
 * @author Jörg P. M. Haeger
 */
class Log {
	pthread_mutex_t mutex;
	int counter;
	String lastLine;
	FILE *outStream;

public:
	Log();

	// conditional logging of debug messages
	void debug(const char *tag, const char *format, ...);
	void debug(const char *tag, String &message);

	/**
	 * log with respect to the current log level
	 */
	void put(int level, const char *message);
	void put(int level, String &message);

	// log important messages
	void put(const char *format, ...);

	// log all messages
	void putv(const char *format, ...);

	/**
	 * Reopen the log file
	 */
	void restart();

	void start(int toStdOut = 0);

private:
	void writeLine(int level, String &line);
};

extern Log log;

#endif
