diff --git a/Makefile.conf b/Makefile.conf index c38246a741..3a0a3fca96 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -8,6 +8,7 @@ SOURCES = \ constants.cpp \ context.cpp \ cssize.cpp \ + debug.cpp \ emitter.cpp \ environment.cpp \ error_handling.cpp \ diff --git a/src/debug.cpp b/src/debug.cpp new file mode 100644 index 0000000000..2bbaac9950 --- /dev/null +++ b/src/debug.cpp @@ -0,0 +1,28 @@ +#include +#include + +#include "debug.hpp" + +namespace Sass { + + Log::Log() {} + + std::ostringstream& Log::Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno) + { + os << "[LIBSASS] " << p << ":" << f << " " << filen << ":" << lineno << " "; + messageLevel = level; + return os; + } + std::ostringstream& Log::Get(TLogLevel level, const char *f, const char *filen, int lineno) + { + os << "[LIBSASS] " << f << " " << filen << ":" << lineno << " "; + messageLevel = level; + return os; + } + Log::~Log() + { + os << std::endl; + fprintf(stderr, "%s", os.str().c_str()); + fflush(stderr); + } +} diff --git a/src/debug.hpp b/src/debug.hpp index 7295f4ea47..f2a142345b 100644 --- a/src/debug.hpp +++ b/src/debug.hpp @@ -1,6 +1,7 @@ #ifndef SASS_DEBUG_H #define SASS_DEBUG_H +#define __STDC_LIMIT_MACROS #include enum dbg_lvl_t : uint32_t { @@ -16,6 +17,40 @@ enum dbg_lvl_t : uint32_t { ALL = UINT32_MAX }; +namespace Sass { + enum TLogLevel {logINFO, logTRACE}; + static TLogLevel LibsassLogReportingLevel = getenv("LIBSASS_TRACE") ? logTRACE : logINFO; + class Log + { + public: + Log(); + virtual ~Log(); + std::ostringstream& Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno); + std::ostringstream& Get(TLogLevel level, const char *f, const char *filen, int lineno); + public: + protected: + std::ostringstream os; + private: + Log(const Log&); + Log& operator =(const Log&); + private: + TLogLevel messageLevel; + }; +} + +// Visual Studio 2013 does not like __func__ +#if _MSC_VER < 1900 +#define __func__ __FUNCTION__ +#endif + +#define TRACE() \ + if (logTRACE > Sass::LibsassLogReportingLevel) ; \ + else Sass::Log().Get(Sass::logTRACE, __func__, __FILE__, __LINE__) + +#define TRACEINST(obj) \ + if (logTRACE > Sass::LibsassLogReportingLevel) ; \ + else Sass::Log().Get(Sass::logTRACE, (obj), __func__, __FILE__, __LINE__) + #ifdef DEBUG #ifndef DEBUG_LVL diff --git a/src/util.cpp b/src/util.cpp index f04c7d519d..c3a1d248b1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,7 @@ #include "sass.h" +#define __STDC_LIMIT_MACROS +#include + #include "ast.hpp" #include "util.hpp" #include "lexer.hpp" @@ -6,8 +9,6 @@ #include "constants.hpp" #include "utf8/checked.h" -#include - namespace Sass { #define out_of_memory() do { \ diff --git a/win/libsass.vcxproj b/win/libsass.vcxproj index 5050cac3eb..aaf281b297 100644 --- a/win/libsass.vcxproj +++ b/win/libsass.vcxproj @@ -202,6 +202,7 @@ +