142 lines
3.6 KiB
C++
Executable File
142 lines
3.6 KiB
C++
Executable File
/*
|
|
* This file is a part of Winix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2011-2012, 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"
|
|
#include "textstream/textstream.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 & operator<<(const PT::Date & date);
|
|
|
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
SLog & operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
|
|
|
|
|
SLog & TranslateText(const char * str);
|
|
SLog & TranslateText(const wchar_t * str);
|
|
|
|
template<size_t str_size>
|
|
SLog & operator<<(const TranslateTextHelper<const char [str_size]> & raw) { return TranslateText(raw.par); }
|
|
|
|
template<size_t str_size>
|
|
SLog & operator<<(const TranslateTextHelper<const wchar_t [str_size]> & raw){ return TranslateText(raw.par); }
|
|
|
|
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(const 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<typename char_type, size_t stack_size, size_t heap_block_size>
|
|
SLog & SLog::operator<<(const PT::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
|
{
|
|
return PutLog(buf);
|
|
}
|
|
|
|
|
|
template<class LogParam>
|
|
SLog & SLog::PutLog(const LogParam & par)
|
|
{
|
|
if( cur && cur->session )
|
|
cur->session->log_buffer << par;
|
|
|
|
return *this;
|
|
}
|
|
|
|
|
|
extern SLog slog;
|
|
|
|
|
|
#endif
|
|
|