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

Commit 6affb04

Browse files
committed
Add live tracing facility
Set NODESASS_TRACE enviroment variable to any value to get lots of output.
1 parent 0bc5da4 commit 6affb04

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'src/create_string.cpp',
99
'src/custom_function_bridge.cpp',
1010
'src/custom_importer_bridge.cpp',
11+
'src/debug.cpp',
1112
'src/sass_context_wrapper.cpp',
1213
'src/sass_types/boolean.cpp',
1314
'src/sass_types/color.cpp',

src/debug.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdio.h>
2+
#include <sstream>
3+
4+
#include <uv.h>
5+
6+
#include "debug.h"
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 << "[NODESASS@" << uv_thread_self() << "] " << 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 << "[NODESASS@" << uv_thread_self() << "] " << 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+
}

src/debug.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef NODE_SASS_DEBUG_H
2+
#define NODE_SASS_DEBUG_H
3+
4+
#include <sstream>
5+
6+
enum TLogLevel {logINFO, logTRACE};
7+
static TLogLevel LogReportingLevel = getenv("NODESASS_TRACE") ? logTRACE : logINFO;
8+
class Log
9+
{
10+
public:
11+
Log();
12+
virtual ~Log();
13+
std::ostringstream& Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno);
14+
std::ostringstream& Get(TLogLevel level, const char *f, const char *filen, int lineno);
15+
public:
16+
protected:
17+
std::ostringstream os;
18+
private:
19+
Log(const Log&);
20+
Log& operator =(const Log&);
21+
private:
22+
TLogLevel messageLevel;
23+
};
24+
25+
// Visual Studio 2013 does not like __func__
26+
#if _MSC_VER < 1900
27+
#define __func__ __FUNCTION__
28+
#endif
29+
30+
#define TRACE() \
31+
if (logTRACE > LogReportingLevel) ; \
32+
else Log().Get(logTRACE, __func__, __FILE__, __LINE__)
33+
34+
#define TRACEINST(obj) \
35+
if (logTRACE > LogReportingLevel) ; \
36+
else Log().Get(logTRACE, (obj), __func__, __FILE__, __LINE__)
37+
38+
#endif

0 commit comments

Comments
 (0)