/*
 * This source file is part of KEOS (Free 3D Engine)
 * For the latest info, see http://www.keosengine.org/
 * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
 * http://www.gnu.org/copyleft/lesser.txt.
 *
 */

#ifndef KEOS_LOGGER_H
#define KEOS_LOGGER_H

#include "KeosPrerequisites.h"

namespace Keos
{
    //-----------------------------------------------------------------------
    /** Abstract class for loggers.
     *
     */
    class KEOS_EXPORT ILogger
    {
    public :
        
        /** Destructor.
         *
         */
        virtual ~ILogger();

        /** Change logger instance.
         *  The instance past here will be destroyed by Logger, 
         *  it must have dynamically been allocated.
         *  @param pLogger New logger.
         */
        static void SetLogger(ILogger* pLogger);

        /** Log a message.
         *  @param strFormat Format of the message.
         *  @param ... Optional parameters
         */
        static void Log(const char* strFormat, ...);

    protected :

        /** Return the current date.
         *  @return Current date in a string.
         */
        String CurrentDate() const;

        /** Return the current time.
         *  @return Current time in a string.
         */
        String CurrentTime() const;

    private :

        /** Write a message, to redefine in the derived classes.
         *  @param strMessage Message writes.
         */
        virtual void Write(const String& strMessage) = 0;

        /** Destruct the logger instance.
         *  
         */
        static void Destroy();

        //! Pointer on the current logger
        static ILogger* ms_pInstance; 

        friend class CRoot;
    };


    //-----------------------------------------------------------------------
    /** Logger registering messages in a file.
     *
     */
    class KEOS_EXPORT CLoggerFile : public ILogger
    {
    public :

        /** Default constructor.
         *  @param strFilename Log file name.
         */
        CLoggerFile(const String& strFilename = "Output.log");

    private :

        /** Destructor.
         *  
         */
        ~CLoggerFile();

        /** Write a message.
         *  @param strMessage Message writes.
         */
        virtual void Write(const String& strMessage);

        //! Log file
        std::ofstream m_File;
    };

} // namespace Keos

#endif // KEOS_LOGGER_H
