MyGUI  3.0.1
MyGUI_LogStream.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_LogStream.h"
25 #include "MyGUI_LogManager.h"
26 #include <iomanip>
27 #include <time.h>
28 
29 namespace MyGUI
30 {
31 
32  LogStream::LogStream() { }
33  LogStream::~LogStream()
34  {
35  if (mStream.is_open())
36  {
37  mStream.close();
38  release();
39  }
40  }
41 
42  LogStream::LogStream(const std::string& _file) : mFileName(_file)
43  {
44  lock();
45 
46  struct tm *current_time;
47  time_t ctTime; time(&ctTime);
48  current_time = localtime( &ctTime );
49 
50  mStream.open(mFileName.c_str(), std::ios_base::out);
51  if (mStream.is_open())
52  {
53  mStream << " ---------------------------------------------------------------------------------------------------------------------------------- " << std::endl;
54  mStream << " loging report for : "
55  << std::setw(2) << std::setfill('0') << current_time->tm_mon + 1 << "/"
56  << std::setw(2) << std::setfill('0') << current_time->tm_mday << "/"
57  << std::setw(4) << std::setfill('0') << current_time->tm_year + 1900 << " "
58  << std::setw(2) << std::setfill('0') << current_time->tm_hour << ":"
59  << std::setw(2) << std::setfill('0') << current_time->tm_min << ":"
60  << std::setw(2) << std::setfill('0') << current_time->tm_sec << std::endl;
61  mStream << " ---------------------------------------------------------------------------------------------------------------------------------- " << std::endl << std::endl;
62  mStream.close();
63  }
64 
65  release();
66  }
67 
68  void LogStream::start(const std::string& _section, const std::string& _level)
69  {
70  if (mStream.is_open())
71  {
72  mStream.close();
73  release();
74  }
75 
76  lock();
77 
78  struct tm *current_time;
79  time_t ctTime; time(&ctTime);
80  current_time = localtime( &ctTime );
81 
82  if (!mFileName.empty())
83  {
84  mStream.open(mFileName.c_str(), std::ios_base::app);
85  if (mStream.is_open())
86  {
87  mStream << std::setw(2) << std::setfill('0') << current_time->tm_hour << ":"
88  << std::setw(2) << std::setfill('0') << current_time->tm_min << ":"
89  << std::setw(2) << std::setfill('0') << current_time->tm_sec << LogManager::separator
90  << _section << LogManager::separator << _level << LogManager::separator;
91  }
92  }
93  }
94 
95  bool LogStream::getSTDOutputEnabled()
96  {
98  }
99 
101  {
102  if (getSTDOutputEnabled()) std::cout << std::endl;
103  if (mStream.is_open())
104  {
105  mStream << std::endl;
106  mStream.close();
107  }
108  release();
109 
110  return *this;
111  }
112 
113 } // namespace MyGUI