summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2012-04-03 17:14:43 +0200
committerLuboš Luňák <l.lunak@suse.cz>2012-04-03 18:16:38 +0200
commitf46775a206589fb9486833ae2e043731cb6be54f (patch)
tree8ef070fe4e6b1cb8a66fd02bd22b1c515ba2f9eb /sal
parentf4e0cbaa15c2861e87149a62c9c80a9e9b4094b3 (diff)
SAL_DEBUG(), instead of those temporary debug printf's
Diffstat (limited to 'sal')
-rw-r--r--sal/inc/sal/detail/log.h1
-rw-r--r--sal/inc/sal/log.hxx21
-rw-r--r--sal/osl/all/log.cxx13
3 files changed, 29 insertions, 6 deletions
diff --git a/sal/inc/sal/detail/log.h b/sal/inc/sal/detail/log.h
index 6ed6a1d95cb8..bb3d4c610f38 100644
--- a/sal/inc/sal/detail/log.h
+++ b/sal/inc/sal/detail/log.h
@@ -72,6 +72,7 @@ extern "C" {
enum sal_detail_LogLevel {
SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
+ SAL_DETAIL_LOG_LEVEL_DEBUG,
SAL_DETAIL_MAKE_FIXED_SIZE = SAL_MAX_ENUM
};
diff --git a/sal/inc/sal/log.hxx b/sal/inc/sal/log.hxx
index 6a2a17c81a1c..59c11cd02713 100644
--- a/sal/inc/sal/log.hxx
+++ b/sal/inc/sal/log.hxx
@@ -187,8 +187,9 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
SAL_INFO(char const * area, expr),
SAL_INFO_IF(bool condition, char const * area, expr),
- SAL_WARN(char const * area, expr), and
- SAL_WARN_IF(bool condition, char const * area, expr) produce an info resp.
+ SAL_WARN(char const * area, expr),
+ 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++
std::ostringstream. The given expr must be so that the full expression
"stream << expr" is valid, where stream is a variable of type
@@ -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
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
<area> ::= <segment>("."<segment>)*
@@ -312,6 +317,16 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
SAL_DETAIL_ENABLE_LOG_WARN && (condition), \
::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
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 6e7009a82b3d..43d704541a0b 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -77,10 +77,14 @@ char const * toString(sal_detail_LogLevel level) {
return "info";
case SAL_DETAIL_LOG_LEVEL_WARN:
return "warn";
+ case SAL_DETAIL_LOG_LEVEL_DEBUG:
+ return "debug";
}
}
bool report(sal_detail_LogLevel level, char const * area) {
+ if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
+ return true;
assert(area != 0);
char const * env = std::getenv("SAL_LOG");
if (env == 0) {
@@ -152,9 +156,12 @@ void log(
char const * message)
{
std::ostringstream s;
- s << toString(level) << ':' << area << ':' << OSL_DETAIL_GETPID << ':'
- << osl::Thread::getCurrentIdentifier() << ':' << where << message
- << '\n';
+ if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
+ s << toString(level) << ':' << /*no where*/' ' << message << '\n';
+ else
+ s << toString(level) << ':' << area << ':' << OSL_DETAIL_GETPID << ':'
+ << osl::Thread::getCurrentIdentifier() << ':' << where << message
+ << '\n';
std::fputs(s.str().c_str(), stderr);
}