Skip to content

Commit 7c38282

Browse files
committed
Introduce live tracing facility
Set LIBSASS_TRACE to any value in the environment to watch a very verbose output live.
1 parent 7db8a5b commit 7c38282

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ SOURCES = \
120120
contextualize.cpp \
121121
contextualize_eval.cpp \
122122
cssize.cpp \
123+
debug.cpp \
123124
listize.cpp \
124125
error_handling.cpp \
125126
eval.cpp \

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ libsass_la_SOURCES = \
4848
context.cpp context.hpp \
4949
contextualize.cpp contextualize.hpp \
5050
contextualize_eval.cpp contextualize_eval.hpp \
51+
debug.cpp \
5152
error_handling.cpp error_handling.hpp \
5253
eval.cpp eval.hpp \
5354
expand.cpp expand.hpp \

debug.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <sstream>
3+
4+
#include "debug.hpp"
5+
6+
namespace Sass {
7+
8+
Log::Log() {}
9+
10+
std::ostringstream& Log::Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno)
11+
{
12+
os << "[LIBSASS] " << p << ":" << f << " " << filen << ":" << lineno << " ";
13+
messageLevel = level;
14+
return os;
15+
}
16+
std::ostringstream& Log::Get(TLogLevel level, const char *f, const char *filen, int lineno)
17+
{
18+
os << "[LIBSASS] " << f << " " << filen << ":" << lineno << " ";
19+
messageLevel = level;
20+
return os;
21+
}
22+
Log::~Log()
23+
{
24+
os << std::endl;
25+
fprintf(stderr, "%s", os.str().c_str());
26+
fflush(stderr);
27+
}
28+
}

debug.hpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef SASS_DEBUG_H
22
#define SASS_DEBUG_H
33

4+
#define __STDC_LIMIT_MACROS
45
#include <stdint.h>
56

67
enum dbg_lvl_t : uint32_t {
@@ -12,10 +13,44 @@ enum dbg_lvl_t : uint32_t {
1213
EXTEND_COMPOUND = 16,
1314
EXTEND_COMPLEX = 32,
1415
LCS = 64,
15-
EXTEND_OBJECT = 128,
16+
EXTEND_OBJECT = 128,
1617
ALL = UINT32_MAX
1718
};
1819

20+
namespace Sass {
21+
enum TLogLevel {logINFO, logTRACE};
22+
static TLogLevel LibsassLogReportingLevel = getenv("LIBSASS_TRACE") ? logTRACE : logINFO;
23+
class Log
24+
{
25+
public:
26+
Log();
27+
virtual ~Log();
28+
std::ostringstream& Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno);
29+
std::ostringstream& Get(TLogLevel level, const char *f, const char *filen, int lineno);
30+
public:
31+
protected:
32+
std::ostringstream os;
33+
private:
34+
Log(const Log&);
35+
Log& operator =(const Log&);
36+
private:
37+
TLogLevel messageLevel;
38+
};
39+
}
40+
41+
// Visual Studio 2013 does not like __func__
42+
#if _MSC_VER < 1900
43+
#define __func__ __FUNCTION__
44+
#endif
45+
46+
#define TRACE() \
47+
if (logTRACE > Sass::LibsassLogReportingLevel) ; \
48+
else Sass::Log().Get(Sass::logTRACE, __func__, __FILE__, __LINE__)
49+
50+
#define TRACEINST(obj) \
51+
if (logTRACE > Sass::LibsassLogReportingLevel) ; \
52+
else Sass::Log().Get(Sass::logTRACE, (obj), __func__, __FILE__, __LINE__)
53+
1954
#ifdef DEBUG
2055

2156
#ifndef DEBUG_LVL

util.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include<stdint.h>
1+
#define __STDC_LIMIT_MACROS
2+
#include <stdint.h>
23
#include "ast.hpp"
34
#include "util.hpp"
45
#include "prelexer.hpp"

win/libsass.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
<ClCompile Include="..\context.cpp" />
170170
<ClCompile Include="..\contextualize.cpp" />
171171
<ClCompile Include="..\contextualize_eval.cpp" />
172+
<ClCompile Include="..\debug.cpp" />
172173
<ClCompile Include="..\error_handling.cpp" />
173174
<ClCompile Include="..\eval.cpp" />
174175
<ClCompile Include="..\expand.cpp" />

0 commit comments

Comments
 (0)