Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 067b137

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 d2f741f commit 067b137

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

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

debug.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@ enum dbg_lvl_t : uint32_t {
1616
ALL = UINT32_MAX
1717
};
1818

19+
enum TLogLevel {logINFO, logTRACE};
20+
static TLogLevel LogReportingLevel = getenv("LIBSASS_TRACE") ? logTRACE : logINFO;
21+
class Log
22+
{
23+
public:
24+
Log();
25+
virtual ~Log();
26+
std::ostringstream& Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno);
27+
std::ostringstream& Get(TLogLevel level, const char *f, const char *filen, int lineno);
28+
public:
29+
protected:
30+
std::ostringstream os;
31+
private:
32+
Log(const Log&);
33+
Log& operator =(const Log&);
34+
private:
35+
TLogLevel messageLevel;
36+
};
37+
38+
#define TRACE() \
39+
if (logTRACE > LogReportingLevel) ; \
40+
else Log().Get(logTRACE, __func__, __FILE__, __LINE__)
41+
42+
#define TRACEINST(obj) \
43+
if (logTRACE > LogReportingLevel) ; \
44+
else Log().Get(logTRACE, (obj), __func__, __FILE__, __LINE__)
45+
1946
#ifdef DEBUG
2047

2148
#ifndef DEBUG_LVL

0 commit comments

Comments
 (0)