Files
LifeProject/LifeCore/log/NLog.cpp
T
2025-05-13 02:46:21 +03:00

95 lines
2.0 KiB
C++

#include "NLog.h"
//#include <io.h>
#include <cstdio>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <tchar.h>
namespace LifeCore {
NettleLog::NettleLog(LOG_LEVEL _level)
: AbortOnError(true), bOutConsole(true), bOutFile(false), bOutInterface(false), level(_level) {
//TODO: remove allocation of stringstream
stm = new std::stringstream();
}
NettleLog::~NettleLog() {
//std::stringstream stm;
*stm << "\n";
/*stm->seekg (0, std::ios::end);
size_t length = (size_t)stm->tellg();
stm->seekg (0, std::ios::beg);
char* buffer = new char [length + 1];
buffer[length] = 0;
stm->read (buffer,length);*/
//_write(1, buffer, length);
std::string str = stm->str();
std::cout << str;
#if defined(NOS_WINDOWS) && defined(_DEBUG)
OutputDebugString(str.c_str());
#endif
delete stm;
// delete[] buffer;
}
NettleLog& NettleLog::operator <<(bool val) {
*stm << (val ? "true" : "false");
return *this;
}
NettleLog& NettleLog::operator <<(uint32 val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(long val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(unsigned long val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(uint16 val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(uint64 val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(int64 val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(int32 val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(int16 val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(int8 val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(float val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(double val) {
*stm << val;
return *this;
}
NettleLog& NettleLog::operator <<(const String& val) {
*stm << val.c_str();
return *this;
}
NettleLog& NettleLog::operator <<(const char* val) {
*stm << val;
return *this;
}
}