
/* -*- mode: C++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */

// openpluginlib - A plugin interface to openlibraries.

// Copyright (C) 2005-2006 Editopia Inc.
// Released under the LGPL.
// For more information, see http://www.openlibraries.org.

#pragma once

// opl
#include <openpluginlib/pl/config.hpp>

// std
#include <iosfwd>
#include <string>

namespace olib { namespace openpluginlib {

/// Basic logging class; don't use directly, but rather through
/// the Log::Debug, Log::Warning, Log::Critical
class OPENPLUGINLIB_DECLSPEC Log
{
public:
    Log( const Log& );
    ~Log();

    static Log Debug( int level = 3, const std::string& preamble = "" );
    static Log Warning( const std::string& preamble = "" );
    static Log Critical( const std::string& preamble = "" );

    enum LogType { LOG_DEBUG,
		   LOG_WARNING,
		   LOG_CRITICAL };

    static void setDestination( LogType, std::ostream& );
    static void setDestination( std::ostream& );
    
    /// set a log level:
    /// - 0 == all off
    /// - 1 == critical
    /// - 2 == warning
    /// - 3+ == debug
    static void setLogLevel( int i );

    std::ostream& operator<<( const std::string& );

private:
    Log( LogType, int level, const std::string& preamble );

    LogType type_;
    std::ostream* os_;
};

} }

namespace pl = olib::openpluginlib;

#define STANDARD_PREAMBLE __FILE__ << ", L" << __LINE__ << ", " << __FUNCTION__ << ":"
#define DEBUG_LOG pl::Log( pl::Log::Debug( 3, "debug: " ) ) << STANDARD_PREAMBLE
#define DEBUG_LOG_V pl::Log( pl::Log::Debug( 4, "debug: " ) ) << STANDARD_PREAMBLE
#define DEBUG_LOG_VV pl::Log( pl::Log::Debug( 5, "debug: " ) ) << STANDARD_PREAMBLE
#define WARNING_LOG pl::Log( pl::Log::Warning( "warning: " ) ) << STANDARD_PREAMBLE
#define CRITICAL_LOG pl::Log( pl::Log::Critical( "critical: " ) ) << STANDARD_PREAMBLE

