/* * This file is a part of Winix * and is distributed under the 2-Clause BSD licence. * Author: Tomasz Sowa */ /* * Copyright (c) 2011-2014, Tomasz Sowa * All rights reserved. * * 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. * */ #ifndef headerfile_winix_core_slog #define headerfile_winix_core_slog #include "cur.h" #include "logmanipulators.h" #include "templates/locale.h" #include "textstream/textstream.h" namespace Winix { #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 struct TranslateTextHelper { const RawType & par; TranslateTextHelper(const TranslateTextHelper & 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 SLog & operator<<(const pt::TextStreamBase & buf); SLog & TranslateText(const char * str); SLog & TranslateText(const wchar_t * str); template SLog & operator<<(const TranslateTextHelper & raw) { return TranslateText(raw.par); } template SLog & operator<<(const TranslateTextHelper & raw){ return TranslateText(raw.par); } template SLog & operator<<(const TranslateTextHelper & raw) { return TranslateText(raw.par); } template SLog & operator<<(const TranslateTextHelper & raw){ return TranslateText(raw.par); } SLog & operator<<(const TranslateTextHelper & raw); SLog & operator<<(const TranslateTextHelper & raw); SLog & operator<<(TranslateTextHelper raw); SLog & operator<<(TranslateTextHelper raw); SLog & operator<<(TranslateTextHelper raw); SLog & operator<<(TranslateTextHelper raw); private: template SLog & PutLog(const LogParam & par); Cur * cur; Locale * locale; std::wstring key_temp; }; template SLog::TranslateTextHelper T(const RawType & par) { return SLog::TranslateTextHelper(par); } template SLog & SLog::operator<<(const pt::TextStreamBase & buf) { return PutLog(buf); } template SLog & SLog::PutLog(const LogParam & par) { if( cur && cur->session ) cur->session->log_buffer << par; return *this; } } // namespace Winix #endif