Skip to content

Commit

Permalink
Introduce live tracing facility
Browse files Browse the repository at this point in the history
Set LIBSASS_TRACE to any value
in the environment to watch
a very verbose output live.

Conflicts:
	Makefile
	Makefile.am
	src/debug.hpp
	src/util.cpp
	win/libsass.vcxproj
  • Loading branch information
saper committed Aug 1, 2015
1 parent 295b152 commit ebed252
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SOURCES = \
constants.cpp \
context.cpp \
cssize.cpp \
debug.cpp \
emitter.cpp \
environment.cpp \
error_handling.cpp \
Expand Down
28 changes: 28 additions & 0 deletions src/debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <sstream>

#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);
}
}
35 changes: 35 additions & 0 deletions src/debug.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef SASS_DEBUG_H
#define SASS_DEBUG_H

#define __STDC_LIMIT_MACROS
#include <stdint.h>

enum dbg_lvl_t : uint32_t {
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "sass.h"
#define __STDC_LIMIT_MACROS
#include <stdint.h>

#include "ast.hpp"
#include "util.hpp"
#include "lexer.hpp"
#include "prelexer.hpp"
#include "constants.hpp"
#include "utf8/checked.h"

#include <stdint.h>

namespace Sass {

#define out_of_memory() do { \
Expand Down
1 change: 1 addition & 0 deletions win/libsass.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<ClCompile Include="..\src\color_maps.cpp" />
<ClCompile Include="..\src\constants.cpp" />
<ClCompile Include="..\src\context.cpp" />
<ClCompile Include="..\src\debug.cpp" />
<ClCompile Include="..\src\environment.cpp" />
<ClCompile Include="..\src\error_handling.cpp" />
<ClCompile Include="..\src\eval.cpp" />
Expand Down

0 comments on commit ebed252

Please sign in to comment.