2011-06-19 22:59:58 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
2014-10-04 20:04:03 +02:00
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2014-02-12 17:30:49 +01:00
|
|
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
2011-06-19 22:59:58 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2014-10-04 20:04:03 +02:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2011-06-19 22:59:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef headerfile_winix_core_slog
|
|
|
|
#define headerfile_winix_core_slog
|
|
|
|
|
|
|
|
#include "cur.h"
|
|
|
|
#include "logmanipulators.h"
|
|
|
|
#include "templates/locale.h"
|
2012-10-27 09:44:26 +02:00
|
|
|
#include "textstream/textstream.h"
|
2011-06-19 22:59:58 +02:00
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-19 22:59:58 +02:00
|
|
|
#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);
|
2021-05-20 20:59:12 +02:00
|
|
|
SLog & operator<<(const pt::Date & date);
|
2012-10-27 09:44:26 +02:00
|
|
|
|
|
|
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
2021-05-20 20:59:12 +02:00
|
|
|
SLog & operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf);
|
2012-10-27 09:44:26 +02:00
|
|
|
|
2011-06-19 22:59:58 +02:00
|
|
|
|
|
|
|
SLog & TranslateText(const char * str);
|
|
|
|
SLog & TranslateText(const wchar_t * str);
|
|
|
|
|
2011-07-07 19:02:14 +02:00
|
|
|
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); }
|
|
|
|
|
2011-06-19 22:59:58 +02:00
|
|
|
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>
|
2012-10-27 09:44:26 +02:00
|
|
|
SLog & PutLog(const LogParam & par);
|
2011-06-19 22:59:58 +02:00
|
|
|
|
|
|
|
Cur * cur;
|
|
|
|
Locale * locale;
|
|
|
|
std::wstring key_temp;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<class RawType>
|
|
|
|
SLog::TranslateTextHelper<RawType> T(const RawType & par)
|
|
|
|
{
|
|
|
|
return SLog::TranslateTextHelper<RawType>(par);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-27 09:44:26 +02:00
|
|
|
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
2021-05-20 20:59:12 +02:00
|
|
|
SLog & SLog::operator<<(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & buf)
|
2012-10-27 09:44:26 +02:00
|
|
|
{
|
|
|
|
return PutLog(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-19 22:59:58 +02:00
|
|
|
template<class LogParam>
|
2012-10-27 09:44:26 +02:00
|
|
|
SLog & SLog::PutLog(const LogParam & par)
|
2011-06-19 22:59:58 +02:00
|
|
|
{
|
|
|
|
if( cur && cur->session )
|
|
|
|
cur->session->log_buffer << par;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
2011-06-19 22:59:58 +02:00
|
|
|
#endif
|
|
|
|
|