MyGUI  3.2.1
MyGUI_FileLogListener.cpp
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #include "MyGUI_Precompiled.h"
00008 #include "MyGUI_FileLogListener.h"
00009 #include <iomanip>
00010 #include <time.h>
00011 
00012 namespace MyGUI
00013 {
00014 
00015     FileLogListener::FileLogListener()
00016     {
00017     }
00018 
00019     FileLogListener::~FileLogListener()
00020     {
00021     }
00022 
00023     void FileLogListener::open()
00024     {
00025         /*time_t ctTime;
00026         time(&ctTime);
00027         struct tm *currentTime;
00028         currentTime = localtime(&ctTime);*/
00029 
00030         mStream.open(mFileName.c_str(), std::ios_base::out);
00031 
00032         /*log(
00033             "Log",
00034             LogLevel::Info,
00035             currentTime,
00036             LogStream()
00037                 << "Log file created "
00038                 << std::setw(2) << std::setfill('0') << currentTime->tm_mday << "."
00039                 << std::setw(2) << std::setfill('0') << (currentTime->tm_mon + 1) << "."
00040                 << std::setw(2) << std::setfill('0') << (currentTime->tm_year + 1900) <<
00041                 LogStream::End(),
00042             __FILE__, __LINE__);*/
00043     }
00044 
00045     void FileLogListener::close()
00046     {
00047         if (mStream.is_open())
00048             mStream.close();
00049     }
00050 
00051     void FileLogListener::flush()
00052     {
00053         if (mStream.is_open())
00054             mStream.flush();
00055     }
00056 
00057     void FileLogListener::log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line)
00058     {
00059         if (mStream.is_open())
00060         {
00061             const char* separator = "  |  ";
00062             mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":"
00063                 << std::setw(2) << std::setfill('0') << _time->tm_min << ":"
00064                 << std::setw(2) << std::setfill('0') << _time->tm_sec << separator
00065                 << _section << separator << _level.print() << separator
00066                 << _message << separator << _file << separator << _line << std::endl;
00067         }
00068     }
00069 
00070     void FileLogListener::setFileName(const std::string& _value)
00071     {
00072         mFileName = _value;
00073     }
00074 
00075     const std::string& FileLogListener::getFileName() const
00076     {
00077         return mFileName;
00078     }
00079 
00080 } // namespace MyGUI