Skip to content

Commit cbaaa1a

Browse files
committed
Move logger into Sass namespace
1 parent 6ec5563 commit cbaaa1a

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

debug.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33

44
#include "debug.hpp"
55

6-
Log::Log() {}
6+
namespace Sass {
77

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);
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+
}
2528
}

debug.hpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,34 @@ 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-
};
19+
namespace Sass {
20+
enum TLogLevel {logINFO, logTRACE};
21+
static TLogLevel LibsassLogReportingLevel = getenv("LIBSASS_TRACE") ? logTRACE : logINFO;
22+
class Log
23+
{
24+
public:
25+
Log();
26+
virtual ~Log();
27+
std::ostringstream& Get(TLogLevel level, void *p, const char *f, const char *filen, int lineno);
28+
std::ostringstream& Get(TLogLevel level, const char *f, const char *filen, int lineno);
29+
public:
30+
protected:
31+
std::ostringstream os;
32+
private:
33+
Log(const Log&);
34+
Log& operator =(const Log&);
35+
private:
36+
TLogLevel messageLevel;
37+
};
38+
}
3739

3840
#define TRACE() \
39-
if (logTRACE > LogReportingLevel) ; \
40-
else Log().Get(logTRACE, __func__, __FILE__, __LINE__)
41+
if (logTRACE > Sass::LibsassLogReportingLevel) ; \
42+
else Sass::Log().Get(Sass::logTRACE, __func__, __FILE__, __LINE__)
4143

4244
#define TRACEINST(obj) \
43-
if (logTRACE > LogReportingLevel) ; \
44-
else Log().Get(logTRACE, (obj), __func__, __FILE__, __LINE__)
45+
if (logTRACE > Sass::LibsassLogReportingLevel) ; \
46+
else Sass::Log().Get(Sass::logTRACE, (obj), __func__, __FILE__, __LINE__)
4547

4648
#ifdef DEBUG
4749

0 commit comments

Comments
 (0)