- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# ScopeLogger.h

Go to the documentation of this file.

    00001
    00015 #pragma once
    00016
    00017 #include "LogLevel.h"
    00018 #include "CompositeLoggable.h"
    00019 #include "ChainLoggable.h"
    00020 #include "FormattedChainLoggable.h"
    00021 #include "Logger.h"
    00022 #include "TStd.h"
    00023
    00027 #define DEFINE_LOGGER(name)                                             \
    00028 class _ScopeLoggerWrapper {                                             \
    00029 public:                                                                 \
    00030     static Nvidia::Logging::ScopeLogger& GetScopeLogger()               \
    00031     {                                                                   \
    00032         static Nvidia::Logging::ScopeLogger scopeLogger((name));        \
    00033         return scopeLogger;                                             \
    00034     }                                                                   \
    00035 }
    00036
    00049 #define LOG(logLevel, message)                                                         \
    00050 {                                                                                      \
    00051     using namespace Nvidia::Logging;                                                   \
    00052     if ( !_ScopeLoggerWrapper::GetScopeLogger().IsFiltered((LogLevel_ ## logLevel)) )  \
    00053     {                                                                                  \
    00054             _ScopeLoggerWrapper::GetScopeLogger().Log((LogLevel_ ## logLevel),         \
    00055             MakeChainLoggable(MakeEmptyChain() + message),                             \
    00056             _T(__FUNCTION__), __LINE__, _T(__FILE__));                                 \
    00057     }                                                                                  \
    00058 }
    00059
    00075 #define LOGF(logLevel, format, message)                                                \
    00076 {                                                                                      \
    00077     using namespace Nvidia::Logging;                                                   \
    00078     if ( !_ScopeLoggerWrapper::GetScopeLogger().IsFiltered((LogLevel_ ## logLevel)) )  \
    00079     {                                                                                  \
    00080         _ScopeLoggerWrapper::GetScopeLogger().Log((LogLevel_ ## logLevel),             \
    00081             MakeFormattedChainLoggable(MakeEmptyChain() + message, format),            \
    00082             _T(__FUNCTION__), __LINE__, _T(__FILE__));                                 \
    00083     }                                                                                  \
    00084 }
    00085
    00086 namespace Nvidia {
    00087 namespace Logging {
    00088
    00096 class ScopeLogger
    00097 {
    00098 private:
    00100     std::tstring m_name;
    00101
    00107     LogLevel m_maximumLogLevel;
    00108
    00109 public:
    00118     ScopeLogger(const std::tstring& name);
    00119
    00125     void Log(LogLevel logLevel, const CompositeLoggable& message, std::tstring functionName, int lineNumber, std::tstring fileName);
    00126
    00128     bool IsFiltered(LogLevel logLevel);
    00129 };
    00130
    00131 inline ScopeLogger::ScopeLogger(const std::tstring& name) :
    00132     m_name(name),
    00133     m_maximumLogLevel(Logger::GetLogger().GetMaximumLogLevel(name)) {}
    00134
    00135 inline void ScopeLogger::Log(LogLevel logLevel, const CompositeLoggable& message, std::tstring functionName, int lineNumber, std::tstring fileName)
    00136 {
    00137     LogInfo logInfo(logLevel, m_name, functionName, fileName, lineNumber);
    00138     Logger::GetLogger().Log(logInfo, message);
    00139 }
    00140
    00141 inline bool ScopeLogger::IsFiltered(LogLevel logLevel)
    00142 {
    00143     return logLevel > m_maximumLogLevel;
    00144 }
    00145
    00146 }
    00147 }