Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_LogStream.h"
00025 #include "MyGUI_LogManager.h"
00026 #include <iomanip>
00027 #include <time.h>
00028
00029 namespace MyGUI
00030 {
00031
00032 LogStream::LogStream() { }
00033 LogStream::~LogStream()
00034 {
00035 if (mStream.is_open()) {
00036 mStream.close();
00037 release();
00038 }
00039 }
00040
00041 LogStream::LogStream(const std::string& _file) : mFileName(_file)
00042 {
00043 lock();
00044
00045 struct tm *current_time;
00046 time_t ctTime; time(&ctTime);
00047 current_time = localtime( &ctTime );
00048
00049 mStream.open(mFileName.c_str(), std::ios_base::out);
00050 if (mStream.is_open()) {
00051 mStream << " ---------------------------------------------------------------------------------------------------------------------------------- " << std::endl;
00052 mStream << " loging report for : "
00053 << std::setw(2) << std::setfill('0') << current_time->tm_mon + 1 << "/"
00054 << std::setw(2) << std::setfill('0') << current_time->tm_mday << "/"
00055 << std::setw(4) << std::setfill('0') << current_time->tm_year + 1900 << " "
00056 << std::setw(2) << std::setfill('0') << current_time->tm_hour << ":"
00057 << std::setw(2) << std::setfill('0') << current_time->tm_min << ":"
00058 << std::setw(2) << std::setfill('0') << current_time->tm_sec << std::endl;
00059 mStream << " ---------------------------------------------------------------------------------------------------------------------------------- " << std::endl << std::endl;
00060 mStream.close();
00061 }
00062
00063 release();
00064 }
00065
00066 void LogStream::start(const std::string& _section, const std::string& _level)
00067 {
00068 if (mStream.is_open()) {
00069 mStream.close();
00070 release();
00071 }
00072
00073 lock();
00074
00075 struct tm *current_time;
00076 time_t ctTime; time(&ctTime);
00077 current_time = localtime( &ctTime );
00078
00079 if (false == mFileName.empty()) {
00080 mStream.open(mFileName.c_str(), std::ios_base::app);
00081 if (mStream.is_open()) {
00082 mStream << std::setw(2) << std::setfill('0') << current_time->tm_hour << ":"
00083 << std::setw(2) << std::setfill('0') << current_time->tm_min << ":"
00084 << std::setw(2) << std::setfill('0') << current_time->tm_sec << LogManager::separator
00085 << _section << LogManager::separator << _level << LogManager::separator;
00086 }
00087 }
00088 }
00089
00090 bool LogStream::getSTDOutputEnabled()
00091 {
00092 return LogManager::getSTDOutputEnabled();
00093 }
00094
00095 LogStream& LogStream::operator<<(const LogStreamEnd& _endl)
00096 {
00097 if (getSTDOutputEnabled()) std::cout << std::endl;
00098 if (mStream.is_open())
00099 {
00100 mStream << std::endl;
00101 mStream.close();
00102 }
00103 release();
00104
00105 return *this;
00106 }
00107
00108 }