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:
122
core/slog.h
Executable file
122
core/slog.h
Executable file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2011, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_core_slog
|
||||
#define headerfile_winix_core_slog
|
||||
|
||||
#include "cur.h"
|
||||
#include "logmanipulators.h"
|
||||
#include "templates/locale.h"
|
||||
|
||||
|
||||
#define WINIX_SLOG_MAX_LOG_SIZE 10240
|
||||
|
||||
|
||||
/*
|
||||
session logger
|
||||
|
||||
sample:
|
||||
#include "log.h" (or slog.h)
|
||||
slog << logerror << "message" << "something" << logend;
|
||||
slog << logwarning << T("message_to_translate") << x << logend;
|
||||
|
||||
if the latter example "message_to_translate" will be taken from locales
|
||||
currently following manipulators are taken into account:
|
||||
loginfo - the message in a normal info
|
||||
logwarning - this is a warning
|
||||
logerror - this is an error
|
||||
logend - end of a line -- we have one kind of a message (info, warning, error) per line
|
||||
|
||||
loginfo, logwarning, logerror should be specified at the beginning of a line
|
||||
(other manipulators are skipped)
|
||||
*/
|
||||
class SLog
|
||||
{
|
||||
public:
|
||||
|
||||
SLog();
|
||||
|
||||
void SetCur(Cur * pcur);
|
||||
void SetLocale(Locale * plocale);
|
||||
|
||||
template<class RawType>
|
||||
struct TranslateTextHelper
|
||||
{
|
||||
const RawType & par;
|
||||
|
||||
TranslateTextHelper(const TranslateTextHelper<RawType> & p) : par(p.par) {}
|
||||
TranslateTextHelper(const RawType & p) : par(p) {}
|
||||
};
|
||||
|
||||
SLog & operator<<(const void * s);
|
||||
SLog & operator<<(const char * s);
|
||||
SLog & operator<<(const std::string * s);
|
||||
SLog & operator<<(const std::string & s);
|
||||
SLog & operator<<(const wchar_t * s);
|
||||
SLog & operator<<(const std::wstring * s);
|
||||
SLog & operator<<(const std::wstring & s);
|
||||
SLog & operator<<(int s);
|
||||
SLog & operator<<(long s);
|
||||
SLog & operator<<(char s);
|
||||
SLog & operator<<(wchar_t s);
|
||||
SLog & operator<<(size_t s);
|
||||
SLog & operator<<(double s);
|
||||
SLog & operator<<(LogManipulators m);
|
||||
|
||||
SLog & TranslateText(const char * str);
|
||||
SLog & TranslateText(const wchar_t * str);
|
||||
|
||||
template<size_t str_size>
|
||||
SLog & operator<<(const TranslateTextHelper<char [str_size]> & raw) { return TranslateText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
SLog & operator<<(const TranslateTextHelper<wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
||||
|
||||
SLog & operator<<(const TranslateTextHelper<const char*> & raw);
|
||||
SLog & operator<<(const TranslateTextHelper<const wchar_t*> & raw);
|
||||
SLog & operator<<(TranslateTextHelper<const std::string*> raw);
|
||||
SLog & operator<<(TranslateTextHelper<const std::wstring*> raw);
|
||||
SLog & operator<<(TranslateTextHelper<std::string> raw);
|
||||
SLog & operator<<(TranslateTextHelper<std::wstring> raw);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
template<class LogParam>
|
||||
SLog & PutLog(LogParam par);
|
||||
|
||||
Cur * cur;
|
||||
Locale * locale;
|
||||
std::wstring key_temp;
|
||||
|
||||
};
|
||||
|
||||
|
||||
template<class RawType>
|
||||
SLog::TranslateTextHelper<RawType> T(const RawType & par)
|
||||
{
|
||||
return SLog::TranslateTextHelper<RawType>(par);
|
||||
}
|
||||
|
||||
|
||||
template<class LogParam>
|
||||
SLog & SLog::PutLog(LogParam par)
|
||||
{
|
||||
if( cur && cur->session )
|
||||
cur->session->log_buffer << par;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
extern SLog slog;
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user