MyGUI  3.2.0
MyGUI_FileLogListener.cpp
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #include "MyGUI_Precompiled.h"
00023 #include "MyGUI_FileLogListener.h"
00024 #include <iomanip>
00025 #include <time.h>
00026 
00027 namespace MyGUI
00028 {
00029 
00030     FileLogListener::FileLogListener()
00031     {
00032     }
00033 
00034     FileLogListener::~FileLogListener()
00035     {
00036     }
00037 
00038     void FileLogListener::open()
00039     {
00040         /*time_t ctTime;
00041         time(&ctTime);
00042         struct tm *currentTime;
00043         currentTime = localtime(&ctTime);*/
00044 
00045         mStream.open(mFileName.c_str(), std::ios_base::out);
00046 
00047         /*log(
00048             "Log",
00049             LogLevel::Info,
00050             currentTime,
00051             LogStream()
00052                 << "Log file created "
00053                 << std::setw(2) << std::setfill('0') << currentTime->tm_mday << "."
00054                 << std::setw(2) << std::setfill('0') << (currentTime->tm_mon + 1) << "."
00055                 << std::setw(2) << std::setfill('0') << (currentTime->tm_year + 1900) <<
00056                 LogStream::End(),
00057             __FILE__, __LINE__);*/
00058     }
00059 
00060     void FileLogListener::close()
00061     {
00062         if (mStream.is_open())
00063             mStream.close();
00064     }
00065 
00066     void FileLogListener::flush()
00067     {
00068         if (mStream.is_open())
00069             mStream.flush();
00070     }
00071 
00072     void FileLogListener::log(const std::string& _section, LogLevel _level, const struct tm* _time, const std::string& _message, const char* _file, int _line)
00073     {
00074         if (mStream.is_open())
00075         {
00076             const char* separator = "  |  ";
00077             mStream << std::setw(2) << std::setfill('0') << _time->tm_hour << ":"
00078                 << std::setw(2) << std::setfill('0') << _time->tm_min << ":"
00079                 << std::setw(2) << std::setfill('0') << _time->tm_sec << separator
00080                 << _section << separator << _level.print() << separator
00081                 << _message << separator << _file << separator << _line << std::endl;
00082         }
00083     }
00084 
00085     void FileLogListener::setFileName(const std::string& _value)
00086     {
00087         mFileName = _value;
00088     }
00089 
00090     const std::string& FileLogListener::getFileName() const
00091     {
00092         return mFileName;
00093     }
00094 
00095 } // namespace MyGUI