git-hooks/pre-commit | 3 +++ sal/inc/rtl/oustringostreaminserter.hxx | 16 ++++++++-------- sal/inc/rtl/ustring.hxx | 5 +++++ sal/inc/sal/detail/log.h | 1 + sal/inc/sal/log.hxx | 29 ++++++++++++++++++++--------- sal/osl/all/log.cxx | 13 ++++++++++--- 6 files changed, 47 insertions(+), 20 deletions(-)
New commits: commit 2ac5b08361bf0c7c98ff9bc10869e2b41c9d85fd Author: LuboÅ¡ LuÅák <l.lu...@suse.cz> Date: Tue Apr 3 17:29:08 2012 +0200 try including the ostream<<OUString operator directly with OUString The theory is that - the operator is suboptimal, because it always uses utf-8 as the encoding, which might possibly lead to some encoding problem somewhere but - the SAL_LOG macros need it anyway, or they are otherwise cumbersome with OUString - as people learn to use the macros more, rtl/oustringostreaminserter.hxx will be included in more and more places, eventually possibly triggering the above problem anyway - people probably should not just blindly do ostream << oustring if they have special encoding requirements So let's try to simply always have the operator available and see how it works out. diff --git a/sal/inc/rtl/oustringostreaminserter.hxx b/sal/inc/rtl/oustringostreaminserter.hxx index 632bc23..28d7c17 100644 --- a/sal/inc/rtl/oustringostreaminserter.hxx +++ b/sal/inc/rtl/oustringostreaminserter.hxx @@ -34,14 +34,6 @@ #include "rtl/textenc.h" #include "rtl/ustring.hxx" -/** Include this header to support rtl::OUString in std::ostream (and thus in - CPPUNIT_ASSERT macros, for example). - - The rtl::OUString is converted to UTF-8. - - @since LibreOffice 3.5. -*/ - // The unittest uses slightly different code to help check that the proper // calls are made. The class is put into a different namespace to make // sure the compiler generates a different (if generating also non-inline) @@ -57,6 +49,14 @@ namespace rtl { #undef rtl #endif +/** + Support for rtl::OUString in std::ostream (and thus in + CPPUNIT_ASSERT or SAL_INFO macros, for example). + + The rtl::OUString is converted to UTF-8. + + @since LibreOffice 3.5. +*/ template< typename charT, typename traits > std::basic_ostream<charT, traits> & operator <<( std::basic_ostream<charT, traits> & stream, rtl::OUString const & string) diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx index ee1ba7f..093b6c9 100644 --- a/sal/inc/rtl/ustring.hxx +++ b/sal/inc/rtl/ustring.hxx @@ -2085,4 +2085,9 @@ inline OString OUStringToOString( const OUString & rUnicode, #endif /* _RTL_USTRING_HXX */ +// Include the ostream << operator directly here, so that it's always available +// for SAL_INFO etc. Make sure it's outside of #ifdef _RTL_USTRING_HXX, because +// includes ustring.hxx back. +#include <rtl/oustringostreaminserter.hxx> + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/inc/sal/log.hxx b/sal/inc/sal/log.hxx index 59c11cd..bb41a6f 100644 --- a/sal/inc/sal/log.hxx +++ b/sal/inc/sal/log.hxx @@ -197,13 +197,9 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) { SAL_INFO("foo", "string " << s << " of length " << n) - would be an example of such a call; if the given s is of type rtl::OUString, + would be an example of such a call. - \#include "rtl/oustringostreaminserter.hxx" - - would make sure that an appropriate operator << is available. - - In either case, the composed message should be in UTF-8 and it should + In the composed message should be in UTF-8 and it should contain no vertical formatting characters and no null characters For the _IF variants, log output is only generated if the given condition is commit 7d540bd08ea06c95d5ac27530b8386ae1bea6526 Author: LuboÅ¡ LuÅák <l.lu...@suse.cz> Date: Tue Apr 3 17:17:06 2012 +0200 commit hook preventing commits with SAL_DEBUG diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit index 2e1ebf8..495dc16 100755 --- a/git-hooks/pre-commit +++ b/git-hooks/pre-commit @@ -64,6 +64,9 @@ sub check_whitespaces($) if (/^(?:[<>=]){7}$/) { bad_line("unresolved merge conflict", $src_full); } + if (/SAL_DEBUG/) { + bad_line("temporary debug in commit", $_, $src_limited); + } } } if ( $found_bad) commit f46775a206589fb9486833ae2e043731cb6be54f Author: LuboÅ¡ LuÅák <l.lu...@suse.cz> Date: Tue Apr 3 17:14:43 2012 +0200 SAL_DEBUG(), instead of those temporary debug printf's diff --git a/sal/inc/sal/detail/log.h b/sal/inc/sal/detail/log.h index 6ed6a1d..bb3d4c6 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 6a2a17c..59c11cd 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 6e7009a..43d7045 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); }
_______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits