Kaydet (Commit) f46775a2 authored tarafından Luboš Luňák's avatar Luboš Luňák

SAL_DEBUG(), instead of those temporary debug printf's

üst f4e0cbaa
...@@ -72,6 +72,7 @@ extern "C" { ...@@ -72,6 +72,7 @@ extern "C" {
enum sal_detail_LogLevel { enum sal_detail_LogLevel {
SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN, SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
SAL_DETAIL_LOG_LEVEL_DEBUG,
SAL_DETAIL_MAKE_FIXED_SIZE = SAL_MAX_ENUM SAL_DETAIL_MAKE_FIXED_SIZE = SAL_MAX_ENUM
}; };
......
...@@ -187,8 +187,9 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) { ...@@ -187,8 +187,9 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
SAL_INFO(char const * area, expr), SAL_INFO(char const * area, expr),
SAL_INFO_IF(bool condition, char const * area, expr), SAL_INFO_IF(bool condition, char const * area, expr),
SAL_WARN(char const * area, expr), and SAL_WARN(char const * area, expr),
SAL_WARN_IF(bool condition, char const * area, expr) produce an info resp. SAL_WARN_IF(bool condition, char const * area, expr), and
SAL_DEBUG(expr) produce an info resp.
warning log entry with a message produced by piping items into a C++ warning log entry with a message produced by piping items into a C++
std::ostringstream. The given expr must be so that the full expression std::ostringstream. The given expr must be so that the full expression
"stream << expr" is valid, where stream is a variable of type "stream << expr" is valid, where stream is a variable of type
...@@ -208,7 +209,11 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) { ...@@ -208,7 +209,11 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
For the _IF variants, log output is only generated if the given condition is For the _IF variants, log output is only generated if the given condition is
true (in addition to the other conditions that have to be met). true (in addition to the other conditions that have to be met).
For all these macros, the given area argument must be non-null and must The SAL_DEBUG macro is for temporary debug statements that are used while
working on code. It is never meant to remain in the code. It will always
simply output the given expression in debug builds.
For all the other macros, the given area argument must be non-null and must
match the regular expression match the regular expression
<area> ::= <segment>("."<segment>)* <area> ::= <segment>("."<segment>)*
...@@ -312,6 +317,16 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) { ...@@ -312,6 +317,16 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
SAL_DETAIL_ENABLE_LOG_WARN && (condition), \ SAL_DETAIL_ENABLE_LOG_WARN && (condition), \
::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream) ::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream)
/**
Produce temporary debugging output from stream. This macro is meant
to be used only while working on code and should never exist in production code.
See @ref sal_log "basic logging functionality" for details.
*/
#define SAL_DEBUG(stream) \
SAL_DETAIL_LOG_STREAM( \
SAL_LOG_TRUE, ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, SAL_WHERE, stream)
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -77,10 +77,14 @@ char const * toString(sal_detail_LogLevel level) { ...@@ -77,10 +77,14 @@ char const * toString(sal_detail_LogLevel level) {
return "info"; return "info";
case SAL_DETAIL_LOG_LEVEL_WARN: case SAL_DETAIL_LOG_LEVEL_WARN:
return "warn"; return "warn";
case SAL_DETAIL_LOG_LEVEL_DEBUG:
return "debug";
} }
} }
bool report(sal_detail_LogLevel level, char const * area) { bool report(sal_detail_LogLevel level, char const * area) {
if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
return true;
assert(area != 0); assert(area != 0);
char const * env = std::getenv("SAL_LOG"); char const * env = std::getenv("SAL_LOG");
if (env == 0) { if (env == 0) {
...@@ -152,9 +156,12 @@ void log( ...@@ -152,9 +156,12 @@ void log(
char const * message) char const * message)
{ {
std::ostringstream s; std::ostringstream s;
s << toString(level) << ':' << area << ':' << OSL_DETAIL_GETPID << ':' if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
<< osl::Thread::getCurrentIdentifier() << ':' << where << message s << toString(level) << ':' << /*no where*/' ' << message << '\n';
<< '\n'; else
s << toString(level) << ':' << area << ':' << OSL_DETAIL_GETPID << ':'
<< osl::Thread::getCurrentIdentifier() << ':' << where << message
<< '\n';
std::fputs(s.str().c_str(), stderr); std::fputs(s.str().c_str(), stderr);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment