added: SLog class -- session logger
messages are displayed in the browser (with locales) changed: MountParser now if there is an error in a line -- the line is simply skipped git-svn-id: svn://ttmath.org/publicrep/winix/trunk@741 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
216
core/slog.cpp
Executable file
216
core/slog.cpp
Executable file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "slog.h"
|
||||
|
||||
|
||||
|
||||
|
||||
SLog::SLog()
|
||||
{
|
||||
cur = 0;
|
||||
locale = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SLog::SetCur(Cur * pcur)
|
||||
{
|
||||
cur = pcur;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SLog::SetLocale(Locale * plocale)
|
||||
{
|
||||
locale = plocale;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const void * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const char * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::string * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::string & s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const wchar_t * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::wstring * s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const std::wstring & s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(int s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(long s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(char s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(wchar_t s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(size_t s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(double s)
|
||||
{
|
||||
return PutLog(s);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(LogManipulators m)
|
||||
{
|
||||
if( cur && cur->session )
|
||||
{
|
||||
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||||
|
||||
switch(m)
|
||||
{
|
||||
case logend:
|
||||
buf << '\n';
|
||||
|
||||
if( buf.Size() > WINIX_SLOG_MAX_LOG_SIZE )
|
||||
{
|
||||
buf.Clear();
|
||||
(*this) << logwarning << T("slog_turn_over") << " " << WINIX_SLOG_MAX_LOG_SIZE << logend;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case loginfo:
|
||||
case logwarning:
|
||||
case logerror:
|
||||
buf << (wchar_t)(int)m;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SLog & SLog::TranslateText(const char * str)
|
||||
{
|
||||
AssignString(str, key_temp);
|
||||
return TranslateText(key_temp.c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::TranslateText(const wchar_t * str)
|
||||
{
|
||||
if( cur && cur->session )
|
||||
{
|
||||
const std::wstring * trans = 0;
|
||||
|
||||
if( locale )
|
||||
trans = &locale->Get(str);
|
||||
|
||||
if( !trans || trans->empty() )
|
||||
cur->session->log_buffer << "Not translated: " << str;
|
||||
else
|
||||
cur->session->log_buffer << trans;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const TranslateTextHelper<const char*> & raw)
|
||||
{
|
||||
return TranslateText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(const TranslateTextHelper<const wchar_t*> & raw)
|
||||
{
|
||||
return TranslateText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<const std::string*> raw)
|
||||
{
|
||||
return TranslateText(raw.par->c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<const std::wstring*> raw)
|
||||
{
|
||||
return TranslateText(raw.par->c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<std::string> raw)
|
||||
{
|
||||
return TranslateText(raw.par.c_str());
|
||||
}
|
||||
|
||||
|
||||
SLog & SLog::operator<<(TranslateTextHelper<std::wstring> raw)
|
||||
{
|
||||
return TranslateText(raw.par.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user