Skip to content

Commit ebed252

Browse files
committed
Introduce live tracing facility
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
1 parent 295b152 commit ebed252

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

Makefile.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ SOURCES = \
88
constants.cpp \
99
context.cpp \
1010
cssize.cpp \
11+
debug.cpp \
1112
emitter.cpp \
1213
environment.cpp \
1314
error_handling.cpp \

src/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+
}

src/debug.hpp

Lines changed: 35 additions & 0 deletions
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 {
@@ -16,6 +17,40 @@ enum dbg_lvl_t : uint32_t {
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

src/util.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include "sass.h"
2+
#define __STDC_LIMIT_MACROS
3+
#include <stdint.h>
4+
25
#include "ast.hpp"
36
#include "util.hpp"
47
#include "lexer.hpp"
58
#include "prelexer.hpp"
69
#include "constants.hpp"
710
#include "utf8/checked.h"
811

9-
#include <stdint.h>
10-
1112
namespace Sass {
1213

1314
#define out_of_memory() do { \

win/libsass.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
<ClCompile Include="..\src\color_maps.cpp" />
203203
<ClCompile Include="..\src\constants.cpp" />
204204
<ClCompile Include="..\src\context.cpp" />
205+
<ClCompile Include="..\src\debug.cpp" />
205206
<ClCompile Include="..\src\environment.cpp" />
206207
<ClCompile Include="..\src\error_handling.cpp" />
207208
<ClCompile Include="..\src\eval.cpp" />

0 commit comments

Comments
 (0)