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 {
00037 mStream.close();
00038 release();
00039 }
00040 }
00041
00042 LogStream::LogStream(const std::string& _file) : mFileName(_file)
00043 {
00044 lock();
00045
00046 struct tm *current_time;
00047 time_t ctTime; time(&ctTime);
00048 current_time = localtime( &ctTime );
00049
00050 mStream.open(mFileName.c_str(), std::ios_base::out);
00051 if (mStream.is_open())
00052 {
00053 mStream << " ---------------------------------------------------------------------------------------------------------------------------------- " << std::endl;
00054 mStream << " loging report for : "
00055 << std::setw(2) << std::setfill('0') << current_time->tm_mon + 1 << "/"
00056 << std::setw(2) << std::setfill('0') << current_time->tm_mday << "/"
00057 << std::setw(4) << std::setfill('0') << current_time->tm_year + 1900 << " "
00058 << std::setw(2) << std::setfill('0') << current_time->tm_hour << ":"
00059 << std::setw(2) << std::setfill('0') << current_time->tm_min << ":"
00060 << std::setw(2) << std::setfill('0') << current_time->tm_sec << std::endl;
00061 mStream << " ---------------------------------------------------------------------------------------------------------------------------------- " << std::endl << std::endl;
00062 mStream.close();
00063 }
00064
00065 release();
00066 }
00067
00068 void LogStream::start(const std::string& _section, const std::string& _level)
00069 {
00070 if (mStream.is_open())
00071 {
00072 mStream.close();
00073 release();
00074 }
00075
00076 lock();
00077
00078 struct tm *current_time;
00079 time_t ctTime; time(&ctTime);
00080 current_time = localtime( &ctTime );
00081
00082 if (!mFileName.empty())
00083 {
00084 mStream.open(mFileName.c_str(), std::ios_base::app);
00085 if (mStream.is_open())
00086 {
00087 mStream << std::setw(2) << std::setfill('0') << current_time->tm_hour << ":"
00088 << std::setw(2) << std::setfill('0') << current_time->tm_min << ":"
00089 << std::setw(2) << std::setfill('0') << current_time->tm_sec << LogManager::separator
00090 << _section << LogManager::separator << _level << LogManager::separator;
00091 }
00092 }
00093 }
00094
00095 bool LogStream::getSTDOutputEnabled()
00096 {
00097 return LogManager::getSTDOutputEnabled();
00098 }
00099
00100 LogStream& LogStream::operator<<(const LogStreamEnd& _endl)
00101 {
00102 if (getSTDOutputEnabled()) std::cout << std::endl;
00103 if (mStream.is_open())
00104 {
00105 mStream << std::endl;
00106 mStream.close();
00107 }
00108 release();
00109
00110 return *this;
00111 }
00112
00113 }