Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic live trace facility #1288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SOURCES = \
constants.cpp \
context.cpp \
cssize.cpp \
debug.cpp \
emitter.cpp \
environment.cpp \
error_handling.cpp \
Expand Down
28 changes: 28 additions & 0 deletions src/debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <sstream>

#include "debug.hpp"

namespace Sass {

Log::Log() {}

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

#define __STDC_LIMIT_MACROS
#include <stdint.h>

enum dbg_lvl_t : uint32_t {
Expand All @@ -16,6 +17,40 @@ enum dbg_lvl_t : uint32_t {
ALL = UINT32_MAX
};

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

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

#ifdef DEBUG

#ifndef DEBUG_LVL
Expand Down
5 changes: 3 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "sass.h"
#define __STDC_LIMIT_MACROS
#include <stdint.h>

#include "ast.hpp"
#include "util.hpp"
#include "lexer.hpp"
#include "prelexer.hpp"
#include "constants.hpp"
#include "utf8/checked.h"

#include <stdint.h>

namespace Sass {

#define out_of_memory() do { \
Expand Down
1 change: 1 addition & 0 deletions win/libsass.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
<ClCompile Include="..\src\color_maps.cpp" />
<ClCompile Include="..\src\constants.cpp" />
<ClCompile Include="..\src\context.cpp" />
<ClCompile Include="..\src\debug.cpp" />
<ClCompile Include="..\src\environment.cpp" />
<ClCompile Include="..\src\error_handling.cpp" />
<ClCompile Include="..\src\eval.cpp" />
Expand Down