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

Commit

Permalink
Add live tracing facility
Browse files Browse the repository at this point in the history
Set NODESASS_TRACE enviroment variable
to any value to get lots of output.
  • Loading branch information
saper committed Apr 30, 2016
1 parent 0bc5da4 commit 6affb04
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'src/create_string.cpp',
'src/custom_function_bridge.cpp',
'src/custom_importer_bridge.cpp',
'src/debug.cpp',
'src/sass_context_wrapper.cpp',
'src/sass_types/boolean.cpp',
'src/sass_types/color.cpp',
Expand Down
27 changes: 27 additions & 0 deletions src/debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
#include <sstream>

#include <uv.h>

#include "debug.h"

Log::Log() {}

std::ostringstream& Log::Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno)
{
os << "[NODESASS@" << uv_thread_self() << "] " << p << ":" << f << " " << filen << ":" << lineno << " ";
messageLevel = level;
return os;
}
std::ostringstream& Log::Get(TLogLevel level, const char *f, const char *filen, int lineno)
{
os << "[NODESASS@" << uv_thread_self() << "] " << f << " " << filen << ":" << lineno << " ";
messageLevel = level;
return os;
}
Log::~Log()
{
os << std::endl;
fprintf(stderr, "%s", os.str().c_str());
fflush(stderr);
}
38 changes: 38 additions & 0 deletions src/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef NODE_SASS_DEBUG_H
#define NODE_SASS_DEBUG_H

#include <sstream>

enum TLogLevel {logINFO, logTRACE};
static TLogLevel LogReportingLevel = getenv("NODESASS_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 > LogReportingLevel) ; \
else Log().Get(logTRACE, __func__, __FILE__, __LINE__)

#define TRACEINST(obj) \
if (logTRACE > LogReportingLevel) ; \
else Log().Get(logTRACE, (obj), __func__, __FILE__, __LINE__)

#endif

0 comments on commit 6affb04

Please sign in to comment.