- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# SimpleTextLogPrinter.h

Go to the documentation of this file.

    00001
    00015 #pragma once
    00016
    00017 #include "GenericLogPrinter.h"
    00018 #include "LogContentsPrinter.h"
    00019 #include "Loggable.h"
    00020 #include "CompositeLoggable.h"
    00021 #include "LogInfo.h"
    00022 #include "RegistryKey.h"
    00023
    00024 #include "TStd.h"
    00025 #include "TBoostFormat.h"
    00026
    00027 #include <boost/utility.hpp>
    00028
    00029 namespace Nvidia {
    00030 namespace Logging {
    00031
    00032 namespace Test {
    00033     class LoggerTest;
    00034     class LoggerConstructorTest;
    00035 }
    00036
    00041 class SimpleContentsPrinter : public LogContentsPrinter, private boost::noncopyable
    00042 {
    00043 private:
    00044     std::tostringstream& m_stream;
    00045 public:
    00046     SimpleContentsPrinter(std::tostringstream& stream);
    00047     void LogContentInternal(const std::tstring& name, const SimpleLoggable& loggable);
    00048     void LogContentInternal(const std::tstring& name, const CompositeLoggable& loggable);
    00049 };
    00050
    00057 class FirstLevelContentsPrinter : public LogContentsPrinter, private boost::noncopyable
    00058 {
    00059 private:
    00060     std::tostringstream& m_stream;
    00061     SimpleContentsPrinter m_simpleContentsPrinter;
    00062 public:
    00063     FirstLevelContentsPrinter(std::tostringstream& stream);
    00064     void LogContentInternal(const std::tstring& name, const SimpleLoggable& loggable);
    00065     void LogContentInternal(const std::tstring& name, const CompositeLoggable& loggable);
    00066 };
    00067
    00079 class SimpleTextLogPrinter : public GenericLogPrinter<std::tstring>
    00080 {
    00081     friend class Nvidia::Logging::Test::LoggerTest;
    00082     friend class Nvidia::Logging::Test::LoggerConstructorTest;
    00083
    00084 private:
    00085     boost::tformat m_formatter;
    00086     std::tostringstream m_stream;
    00087     FirstLevelContentsPrinter m_firstLevelContentsPrinter;
    00088
    00089 public:
    00091     SimpleTextLogPrinter();
    00092
    00098     SimpleTextLogPrinter(const RegistryKey& key);
    00099
    00100 private:
    00106     std::tstring DoFormatMessage(const LogInfo& logInfo, const CompositeLoggable& message);
    00107 };
    00108
    00109 inline SimpleContentsPrinter::SimpleContentsPrinter(std::tostringstream& stream) :
    00110     m_stream(stream) {}
    00111
    00112 inline void SimpleContentsPrinter::LogContentInternal(const std::tstring& name, const SimpleLoggable& loggable)
    00113 {
    00114     if ( name.length() > 0 )
    00115         m_stream << name << _T("=");
    00116
    00117     m_stream << _T("\"") << loggable.GetStringValue() << _T("\" ") ;
    00118 }
    00119
    00120 inline void SimpleContentsPrinter::LogContentInternal(const std::tstring& name, const CompositeLoggable& loggable)
    00121 {
    00122     if ( name.length() > 0 )
    00123         m_stream << name << _T("=");
    00124
    00125     m_stream << loggable.GetHumanReadableTypeName() << _T("( ") ;
    00126
    00127     loggable.LogContentsOn(*this);
    00128     m_stream << _T(") ");
    00129 }
    00130
    00131 inline FirstLevelContentsPrinter::FirstLevelContentsPrinter(std::tostringstream& stream) :
    00132     m_stream(stream),
    00133     m_simpleContentsPrinter(stream) {}
    00134
    00135 inline void FirstLevelContentsPrinter::LogContentInternal(const std::tstring&, const SimpleLoggable&)
    00136 {
    00137     return;
    00138 }
    00139
    00140 inline void FirstLevelContentsPrinter::LogContentInternal(const std::tstring&, const CompositeLoggable& loggable)
    00141 {
    00142     m_stream << loggable.GetHumanReadableTypeName() << _T("( ") ;
    00143     loggable.LogContentsOn(m_simpleContentsPrinter);
    00144     m_stream << _T(") ");
    00145 }
    00146
    00147 inline SimpleTextLogPrinter::SimpleTextLogPrinter() :
    00148     m_stream(),
    00149     m_formatter(_T("%11.3lf | %8x: [%x] %d@%x : %x. ")),
    00150     m_firstLevelContentsPrinter(m_stream) {}
    00151
    00152 inline SimpleTextLogPrinter::SimpleTextLogPrinter(const RegistryKey&) :
    00153     m_stream(),
    00154     m_formatter(_T("%11.3lf | %8x: [%x] %d@%x : %x. ")),
    00155     m_firstLevelContentsPrinter(m_stream) {}
    00156
    00157 inline std::tstring SimpleTextLogPrinter::DoFormatMessage(const LogInfo& logInfo, const CompositeLoggable& message)
    00158 {
    00159     m_formatter % (((double) logInfo.GetRelativeTimestamp()) / 1000);
    00160     m_formatter % Utils::CapitalizeString(boost::lexical_cast<std::tstring>(logInfo.GetLevel()));
    00161     m_formatter % logInfo.GetScopeLoggerName();
    00162     m_formatter % logInfo.GetLineNumber();
    00163     m_formatter % logInfo.GetFunctionName();
    00164     m_formatter % message.GetStringValue();
    00165
    00166     m_stream.str(_T(""));
    00167     m_stream << m_formatter;
    00168     message.LogContentsOn(m_firstLevelContentsPrinter);
    00169     return m_stream.str();
    00170 }
    00171
    00172 }
    00173 }