[Libreoffice-commits] .: avmedia/source basic/inc basic/source canvas/inc cppu/qa desktop/source jvmfwk/plugins sal/inc sal/osl sal/rtl sal/util sfx2/inc sfx2/source smoketestoo_native/smoketest.cxx solenv/bin solenv/gbuild solenv/inc svl/source sw/source tools/inc tools/qa tools/source unotest/inc unotest/prj vcl/source

Stephan Bergmann sbergmann at kemper.freedesktop.org
Tue Nov 22 00:44:01 PST 2011


 avmedia/source/viewer/mediawindowbase_impl.cxx    |   14 -
 basic/inc/basic/sbxcore.hxx                       |    3 
 basic/source/app/app.cxx                          |   17 -
 basic/source/sbx/sbxbase.cxx                      |   25 -
 basic/source/uno/namecont.cxx                     |  208 +++++++--------
 canvas/inc/canvas/verbosetrace.hxx                |   11 
 cppu/qa/cppumaker/test_cppumaker.cxx              |   15 -
 cppu/qa/test_unotype.cxx                          |   15 -
 desktop/source/deployment/registry/dp_backend.cxx |   18 -
 jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h   |   94 ------
 jvmfwk/plugins/sunmajor/pluginlib/util.cxx        |   13 
 sal/inc/osl/diagnose.h                            |   79 ++---
 sal/inc/osl/diagnose.hxx                          |   27 -
 sal/inc/osl/thread.hxx                            |   10 
 sal/inc/rtl/oustringostreaminserter.hxx           |   61 ++++
 sal/inc/rtl/strbuf.hxx                            |   11 
 sal/inc/rtl/string.hxx                            |   19 -
 sal/inc/rtl/ustrbuf.hxx                           |   15 -
 sal/inc/rtl/ustring.hxx                           |   29 +-
 sal/inc/sal/log.h                                 |  305 ++++++++++++++++++++++
 sal/osl/all/formatstring.cxx                      |   61 ----
 sal/osl/all/log.cxx                               |  199 ++++++++++++++
 sal/osl/all/logformat.hxx                         |   49 +++
 sal/osl/all/makefile.mk                           |    8 
 sal/osl/all/printtrace.cxx                        |   68 ----
 sal/osl/all/trace.cxx                             |   48 +++
 sal/osl/inc/printtrace.h                          |   49 ---
 sal/osl/unx/conditn.c                             |  137 ++++-----
 sal/osl/unx/diagnose.c                            |   13 
 sal/osl/w32/diagnose.c                            |   21 -
 sal/rtl/source/logfile.cxx                        |    9 
 sal/util/sal.map                                  |    3 
 sfx2/inc/sfx2/objface.hxx                         |    4 
 sfx2/source/appl/module.cxx                       |   12 
 sfx2/source/control/bindings.cxx                  |   56 +---
 sfx2/source/control/dispatch.cxx                  |   37 --
 sfx2/source/control/shell.cxx                     |   28 --
 smoketestoo_native/smoketest.cxx                  |    2 
 solenv/bin/addsym.awk                             |    7 
 solenv/gbuild/gbuild.mk                           |    8 
 solenv/inc/settings.mk                            |    3 
 svl/source/inc/poolio.hxx                         |    9 
 svl/source/items/itempool.cxx                     |    2 
 svl/source/items/poolio.cxx                       |    9 
 svl/source/items/whassert.hxx                     |   25 -
 sw/source/ui/docvw/srcedtw.cxx                    |   21 -
 tools/inc/tools/debug.hxx                         |  151 ++--------
 tools/qa/cppunit/test_reversemap.cxx              |    2 
 tools/source/debug/debug.cxx                      |  110 ++-----
 tools/source/rc/resmgr.cxx                        |    8 
 unotest/inc/unotest/oustringostreaminserter.hxx   |   55 ---
 unotest/prj/d.lst                                 |    1 
 vcl/source/app/dbggui.cxx                         |   26 -
 53 files changed, 1161 insertions(+), 1069 deletions(-)

New commits:
commit 70a6b9ffbd676a1384433a86205d2cd4f2d4f4b1
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Nov 22 09:34:46 2011 +0100

    New sal/log.h obsoletes osl/diagnose.h and tools/debug.hxx.
    
    * New SAL_INFO..., SAL_WARN... macros.
    * New SAL_STREAM supersedes OSL_FORMAT.
    * oustringostreaminserter.hxx moved from unotest to rtl (and always UTF-8 now).
    * TODO to enable GCC __attribute__((format)) in sal/log.h (requires call-site
      cleanup).
    * Further functionality in tools/debug.hxx (DBG_MEMTEST, DBG_CTOR, etc.) not yet
      addressed.
    * Some replacements tools String -> rtl::OUString.

diff --git a/avmedia/source/viewer/mediawindowbase_impl.cxx b/avmedia/source/viewer/mediawindowbase_impl.cxx
index 77ec02b..3c883a1 100644
--- a/avmedia/source/viewer/mediawindowbase_impl.cxx
+++ b/avmedia/source/viewer/mediawindowbase_impl.cxx
@@ -30,6 +30,8 @@
 #include <avmedia/mediaitem.hxx>
 #include "mediamisc.hxx"
 #include "mediawindow.hrc"
+#include <rtl/oustringostreaminserter.hxx>
+#include <sal/log.h>
 #include <tools/urlobj.hxx>
 #include <comphelper/processfactory.hxx>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -81,14 +83,18 @@ uno::Reference< media::XPlayer > MediaWindowBaseImpl::createPlayer( const ::rtl:
                     xManager->createPlayer( rURL ), uno::UNO_QUERY );
             }
             else
-                OSL_FAIL( "failed to create media player service " AVMEDIA_MANAGER_SERVICE_NAME );
+                SAL_WARN_S(
+                    "avmedia",
+                    ("failed to create media player service "
+                     AVMEDIA_MANAGER_SERVICE_NAME));
         }
         catch( const uno::Exception &e )
         {
             (void)e;
-            OSL_FAIL( OSL_FORMAT( "couldn't create media player '%s', exception '%s'",
-                                  AVMEDIA_MANAGER_SERVICE_NAME,
-                                  rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ) );
+            SAL_WARN_S(
+                "avmedia",
+                "couldn't create media player " AVMEDIA_MANAGER_SERVICE_NAME
+                    ", exception '" << e.Message << '\'');
         }
     }
 
diff --git a/basic/inc/basic/sbxcore.hxx b/basic/inc/basic/sbxcore.hxx
index a4abca6..1969adf 100644
--- a/basic/inc/basic/sbxcore.hxx
+++ b/basic/inc/basic/sbxcore.hxx
@@ -39,6 +39,7 @@
 class SvStream;
 class String;
 class UniString;
+namespace rtl { class OUString; }
 
 // The following Macro defines four (five) necessary methods within a
 // SBX object. LoadPrivateData() and StorePrivateData() must be implemented.
@@ -133,7 +134,7 @@ public:
     static void RemoveFactory( SbxFactory* );
 
     static SbxBase* Create( sal_uInt16, sal_uInt32=SBXCR_SBX );
-    static SbxObject* CreateObject( const String& );
+    static SbxObject* CreateObject( const rtl::OUString& );
 };
 
 #ifndef SBX_BASE_DECL_DEFINED
diff --git a/basic/source/app/app.cxx b/basic/source/app/app.cxx
index 72f3ab0..e017569 100644
--- a/basic/source/app/app.cxx
+++ b/basic/source/app/app.cxx
@@ -70,7 +70,9 @@
 #include <ucbhelper/content.hxx>
 #include <unotools/syslocale.hxx>
 
+#include <rtl/oustringostreaminserter.hxx>
 #include <rtl/strbuf.hxx>
+#include <sal/log.h>
 
 using namespace comphelper;
 using namespace cppu;
@@ -241,8 +243,9 @@ int BasicApp::Main( )
     DbgSetPrintTestTool( DBG_TestToolDebugMessageFilter );
     DBG_INSTOUTERROR( DBG_OUT_TESTTOOL );
 
-    if ( osl_setDebugMessageFunc( osl_TestToolDebugMessageFilter ) )
-        OSL_FAIL("osl_setDebugMessageFunc returns non NULL pointer");
+    SAL_WARN_IF(
+        osl_setDebugMessageFunc(osl_TestToolDebugMessageFilter), "basic",
+        "osl_setDebugMessageFunc returns non NULL pointer");
 #endif
 
     ResMgr::SetReadStringHook( ReplaceStringHookProc );
@@ -1849,12 +1852,10 @@ String BasicFrame::GenRealString( const String &aResString )
         }
         else
         {
-            OSL_FAIL(
-                OSL_FORMAT(
-                    "Unknown replacement in String: %s",
-                    rtl::OUStringToOString(
-                        aResult.Copy(nStart, nEnd - nStart),
-                        RTL_TEXTENCODING_UTF8).getStr()));
+            SAL_WARN_S(
+                "basic",
+                "Unknown replacement in String: "
+                    << rtl::OUString(aResult.Copy(nStart, nEnd - nStart)));
             nStartPos = nStartPos + StartKenn.Len();
         }
     }
diff --git a/basic/source/sbx/sbxbase.cxx b/basic/source/sbx/sbxbase.cxx
index 1520c43..fa831ab 100644
--- a/basic/source/sbx/sbxbase.cxx
+++ b/basic/source/sbx/sbxbase.cxx
@@ -38,7 +38,8 @@
 #include <basic/sbxbase.hxx>
 
 #include <rtl/instance.hxx>
-#include <rtl/strbuf.hxx>
+#include <rtl/oustringostreaminserter.hxx>
+#include <sal/log.h>
 
 // AppData-Structure for SBX:
 
@@ -212,19 +213,11 @@ SbxBase* SbxBase::Create( sal_uInt16 nSbxId, sal_uInt32 nCreator )
         if( pNew )
             break;
     }
-#ifdef DBG_UTIL
-    if( !pNew )
-    {
-        rtl::OStringBuffer aMsg(
-            RTL_CONSTASCII_STRINGPARAM("SBX: Keine Factory fuer SBX-ID "));
-        aMsg.append(static_cast<sal_Int32>(nSbxId));
-        DbgError(aMsg.getStr());
-    }
-#endif
+    SAL_WARN_IF_S(!pNew, "basic", "No factory for SBX ID " << nSbxId);
     return pNew;
 }
 
-SbxObject* SbxBase::CreateObject( const XubString& rClass )
+SbxObject* SbxBase::CreateObject( const rtl::OUString& rClass )
 {
     SbxAppData& r = GetSbxData_Impl();
     SbxObject* pNew = NULL;
@@ -234,15 +227,7 @@ SbxObject* SbxBase::CreateObject( const XubString& rClass )
         if( pNew )
             break;
     }
-#ifdef DBG_UTIL
-    if( !pNew )
-    {
-        ByteString aMsg( "SBX: Keine Factory fuer Objektklasse " );
-        ByteString aClassStr( (const UniString&)rClass, RTL_TEXTENCODING_ASCII_US );
-        aMsg += aClassStr;
-        DbgError( (const char*)aMsg.GetBuffer() );
-    }
-#endif
+    SAL_WARN_IF_S(!pNew, "basic", "No factory for object class " << rClass);
     return pNew;
 }
 
diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index 988c5c9..f7abc39 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -37,9 +37,10 @@
 #include <osl/mutex.hxx>
 #include <tools/errinf.hxx>
 #include <osl/mutex.hxx>
-#include <osl/diagnose.h>
+#include <rtl/oustringostreaminserter.hxx>
 #include <rtl/uri.hxx>
 #include <rtl/strbuf.hxx>
+#include <sal/log.h>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/anytostring.hxx>
 
@@ -382,24 +383,18 @@ SfxLibraryContainer::SfxLibraryContainer( void )
     DBG_CTOR( SfxLibraryContainer, NULL );
 
     mxMSF = comphelper::getProcessServiceFactory();
-    if( !mxMSF.is() )
-    {
-        OSL_FAIL( "couldn't get ProcessServiceFactory" );
-    }
+    SAL_WARN_IF(!mxMSF.is(), "basic", "couldn't get ProcessServiceFactory");
 
     mxSFI = Reference< XSimpleFileAccess >( mxMSF->createInstance
         ( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")) ), UNO_QUERY );
-    if( !mxSFI.is() )
-    {
-        OSL_FAIL( "couldn't create SimpleFileAccess component" );
-    }
+    SAL_WARN_IF(
+        !mxSFI.is(), "basic", "couldn't create SimpleFileAccess component");
 
     mxStringSubstitution = Reference< XStringSubstitution >( mxMSF->createInstance
         ( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.PathSubstitution")) ), UNO_QUERY );
-    if( !mxStringSubstitution.is() )
-    {
-        OSL_FAIL( "couldn't create PathSubstitution component" );
-    }
+    SAL_WARN_IF(
+        !mxStringSubstitution.is(), "basic",
+        "couldn't create PathSubstitution component");
 }
 
 SfxLibraryContainer::~SfxLibraryContainer()
@@ -432,7 +427,10 @@ BasicManager* SfxLibraryContainer::getBasicManager( void )
         return mpBasMgr;
 
     Reference< XModel > xDocument( mxOwnerDocument.get(), UNO_QUERY );
-    OSL_ENSURE( xDocument.is(), "SfxLibraryContainer::getBasicManager: cannot obtain a BasicManager without document!" );
+    SAL_WARN_IF(
+        !xDocument.is(), "basic",
+        ("SfxLibraryContainer::getBasicManager: cannot obtain a BasicManager"
+         " without document!"));
     if ( xDocument.is() )
         mpBasMgr = BasicManagerRepository::getDocumentBasicManager( xDocument );
 
@@ -673,7 +671,7 @@ sal_Bool SfxLibraryContainer::init_Impl(
         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY );
     if( !xParser.is() )
     {
-        OSL_FAIL( "couldn't create sax parser component" );
+        SAL_WARN("basic", "couldn't create sax parser component");
         return sal_False;
     }
 
@@ -697,8 +695,9 @@ sal_Bool SfxLibraryContainer::init_Impl(
     {
         if( bStorage )
         {
-            OSL_ENSURE( meInitMode == DEFAULT || meInitMode == OFFICE_DOCUMENT,
-                "### Wrong InitMode for document\n" );
+            SAL_WARN_IF(
+                meInitMode != DEFAULT && meInitMode != OFFICE_DOCUMENT, "basic",
+                "Wrong InitMode for document");
             try
             {
                 uno::Reference< io::XStream > xStream;
@@ -824,13 +823,13 @@ sal_Bool SfxLibraryContainer::init_Impl(
             catch ( xml::sax::SAXException& e )
             {
                 (void) e; // avoid warning
-                OSL_FAIL( OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
+                SAL_WARN_S("basic", e.Message);
                 return sal_False;
             }
             catch ( io::IOException& e )
             {
                 (void) e; // avoid warning
-                OSL_FAIL( OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
+                SAL_WARN_S("basic", e.Message);
                 return sal_False;
             }
 
@@ -918,16 +917,11 @@ sal_Bool SfxLibraryContainer::init_Impl(
                         {
                         #if OSL_DEBUG_LEVEL > 0
                             Any aError( ::cppu::getCaughtException() );
-                            OSL_FAIL(
-                                OSL_FORMAT(
-                                    ("couldn't open sub storage for library"
-                                     " \"%s\". Exception: %s"),
-                                    (rtl::OUStringToOString(
-                                        rLib.aName, RTL_TEXTENCODING_UTF8).
-                                     getStr()),
-                                    rtl::OUStringToOString(
-                                        comphelper::anyToString(aError),
-                                        RTL_TEXTENCODING_UTF8).getStr()));
+                            SAL_WARN_S(
+                                "basic",
+                                "couldn't open sub storage for library \""
+                                    << rLib.aName << "\". Exception: "
+                                    << comphelper::anyToString(aError));
                         #endif
                         }
                     }
@@ -937,11 +931,10 @@ sal_Bool SfxLibraryContainer::init_Impl(
                     {
                         OUString aIndexFileName;
                         sal_Bool bLoaded = implLoadLibraryIndexFile( pImplLib, rLib, xLibraryStor, aIndexFileName );
-                        if( bLoaded && aLibName != rLib.aName )
-                        {
-                            OSL_FAIL( "Different library names in library"
-                                " container and library info files!" );
-                        }
+                        SAL_WARN_IF(
+                            bLoaded && aLibName != rLib.aName, "basic",
+                            ("Different library names in library container and"
+                             " library info files!"));
                         if( GbMigrationSuppressErrors && !bLoaded )
                             removeLibrary( aLibName );
                     }
@@ -989,7 +982,7 @@ sal_Bool SfxLibraryContainer::init_Impl(
         catch(const uno::Exception& )
         {
             // TODO: error handling?
-            OSL_FAIL( "Cannot access extensions!" );
+            SAL_WARN("basic", "Cannot access extensions!");
         }
     }
 
@@ -1204,7 +1197,7 @@ sal_Bool SfxLibraryContainer::init_Impl(
         // #i93163
         if( bCleanUp )
         {
-            OSL_FAIL( "Upgrade of Basic installation failed somehow" );
+            SAL_WARN("basic", "Upgrade of Basic installation failed somehow");
 
             static char strErrorSavFolderName[] = "__basic_80_err";
             INetURLObject aPrevUserBasicInetObj_Err( aUserBasicInetObj );
@@ -1414,11 +1407,9 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
 
             if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
             {
-                OSL_FAIL(
-                    OSL_FORMAT(
-                        "invalid library element \"%s\"",
-                        rtl::OUStringToOString(
-                            aElementName, RTL_TEXTENCODING_UTF8).getStr()));
+                SAL_WARN_S(
+                    "basic",
+                    "invalid library element \"" << aElementName << '"');
                 continue;
             }
             try {
@@ -1431,7 +1422,9 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
                 OUString aMime( RTL_CONSTASCII_USTRINGPARAM("text/xml") );
 
                 uno::Reference< beans::XPropertySet > xProps( xElementStream, uno::UNO_QUERY );
-                OSL_ENSURE( xProps.is(), "The StorageStream must implement XPropertySet interface!\n" );
+                SAL_WARN_IF(
+                    !xProps.is(), "basic",
+                    "The StorageStream must implement XPropertySet interface!");
                 //if ( !xProps.is() ) //TODO
 
                 if ( xProps.is() )
@@ -1449,7 +1442,7 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
             }
             catch(const uno::Exception& )
             {
-                OSL_FAIL( "Problem during storing of library!" );
+                SAL_WARN("basic", "Problem during storing of library!");
                 // TODO: error handling?
             }
         }
@@ -1496,11 +1489,9 @@ void SfxLibraryContainer::implStoreLibrary( SfxLibrary* pLib,
 
                 if( !isLibraryElementValid( pLib->getByName( aElementName ) ) )
                 {
-                    OSL_FAIL(
-                        OSL_FORMAT(
-                            "invalid library element \"%s\"",
-                            rtl::OUStringToOString(
-                                aElementName, RTL_TEXTENCODING_UTF8).getStr()));
+                    SAL_WARN_S(
+                        "basic",
+                        "invalid library element \"" << aElementName << '"');
                     continue;
                 }
 
@@ -1552,7 +1543,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
             OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ) ), UNO_QUERY );
     if( !xHandler.is() )
     {
-        OSL_FAIL( "couldn't create sax-writer component" );
+        SAL_WARN("basic", "couldn't create sax-writer component");
         return;
     }
 
@@ -1569,7 +1560,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
 
         try {
             xInfoStream = xStorage->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
-            OSL_ENSURE( xInfoStream.is(), "No stream!\n" );
+            SAL_WARN_IF(!xInfoStream.is(), "basic", "No stream!");
             uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY );
             //    throw uno::RuntimeException(); // TODO
 
@@ -1588,7 +1579,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
         }
         catch(const uno::Exception& )
         {
-            OSL_FAIL( "Problem during storing of library index file!" );
+            SAL_WARN("basic", "Problem during storing of library index file!");
             // TODO: error handling?
         }
     }
@@ -1637,7 +1628,7 @@ void SfxLibraryContainer::implStoreLibraryIndexFile( SfxLibrary* pLib,
     }
     if( !xOut.is() )
     {
-        OSL_FAIL( "couldn't open output stream" );
+        SAL_WARN("basic", "couldn't open output stream");
         return;
     }
 
@@ -1655,7 +1646,7 @@ sal_Bool SfxLibraryContainer::implLoadLibraryIndexFile(  SfxLibrary* pLib,
         OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY );
     if( !xParser.is() )
     {
-        OSL_FAIL( "couldn't create sax parser component" );
+        SAL_WARN("basic", "couldn't create sax parser component");
         return sal_False;
     }
 
@@ -1727,7 +1718,7 @@ sal_Bool SfxLibraryContainer::implLoadLibraryIndexFile(  SfxLibrary* pLib,
     }
     catch(const Exception& )
     {
-        OSL_FAIL( "Parsing error" );
+        SAL_WARN("basic", "Parsing error");
         SfxErrorContext aEc( ERRCTX_SFX_LOADBASIC, aLibInfoPath );
         sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
         ErrorHandler::HandleError( nErrorCode );
@@ -1915,15 +1906,11 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
                     {
                     #if OSL_DEBUG_LEVEL > 0
                         Any aError( ::cppu::getCaughtException() );
-                        OSL_FAIL(
-                            OSL_FORMAT(
-                                ("couldn't create sub storage for library"
-                                 " \"%s\". Exception: %s"),
-                                rtl::OUStringToOString(
-                                    rLib.aName, RTL_TEXTENCODING_UTF8).getStr(),
-                                rtl::OUStringToOString(
-                                    comphelper::anyToString(aError),
-                                    RTL_TEXTENCODING_UTF8).getStr()));
+                        SAL_WARN_S(
+                            "basic",
+                            "couldn't create sub storage for library \""
+                                << rLib.aName << "\". Exception: "
+                                << comphelper::anyToString(aError));
                     #endif
                         return;
                     }
@@ -1967,7 +1954,10 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
     // then we need to clean up the temporary storage we used for this
     if ( bInplaceStorage && sTempTargetStorName.getLength() )
     {
-        OSL_ENSURE( xSourceLibrariesStor.is(), "SfxLibrariesContainer::storeLibraries_impl: unexpected: we should have a source storage here!" );
+        SAL_WARN_IF(
+            !xSourceLibrariesStor.is(), "basic",
+            ("SfxLibrariesContainer::storeLibraries_impl: unexpected: we should"
+             " have a source storage here!"));
         try
         {
             // for this, we first remove everything from the source storage, then copy the complete content
@@ -2028,7 +2018,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
             OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Writer") ) ), UNO_QUERY );
     if( !xHandler.is() )
     {
-        OSL_FAIL( "couldn't create sax-writer component" );
+        SAL_WARN("basic", "couldn't create sax-writer component");
         return;
     }
 
@@ -2043,7 +2033,9 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
         try {
             xInfoStream = xTargetLibrariesStor->openStreamElement( aStreamName, embed::ElementModes::READWRITE );
             uno::Reference< beans::XPropertySet > xProps( xInfoStream, uno::UNO_QUERY );
-            OSL_ENSURE ( xProps.is(), "The stream must implement XPropertySet!\n" );
+            SAL_WARN_IF(
+                !xProps.is(), "basic",
+                "The stream must implement XPropertySet!");
             if ( !xProps.is() )
                 throw uno::RuntimeException();
 
@@ -2088,7 +2080,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
     }
     if( !xOut.is() )
     {
-        OSL_FAIL( "couldn't open output stream" );
+        SAL_WARN("basic", "couldn't open output stream");
         return;
     }
 
@@ -2101,7 +2093,9 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
         if ( bStorage )
         {
             uno::Reference< embed::XTransactedObject > xTransact( xTargetLibrariesStor, uno::UNO_QUERY );
-            OSL_ENSURE( xTransact.is(), "The storage must implement XTransactedObject!\n" );
+            SAL_WARN_IF(
+                !xTransact.is(), "basic",
+                "The storage must implement XTransactedObject!");
             if ( !xTransact.is() )
                 throw uno::RuntimeException();
 
@@ -2110,7 +2104,7 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
     }
     catch(const uno::Exception& )
     {
-        OSL_FAIL( "Problem during storing of libraries!" );
+        SAL_WARN("basic", "Problem during storing of libraries!");
         sal_uIntPtr nErrorCode = ERRCODE_IO_GENERAL;
         ErrorHandler::HandleError( nErrorCode );
     }
@@ -2326,12 +2320,18 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
         {
             try {
                 xLibrariesStor = mxStorage->openStorageElement( maLibrariesDir, embed::ElementModes::READ );
-                OSL_ENSURE( xLibrariesStor.is(), "The method must either throw exception or return a storage!\n" );
+                SAL_WARN_IF(
+                    !xLibrariesStor.is(), "basic",
+                    ("The method must either throw exception or return a"
+                     " storage!"));
                 if ( !xLibrariesStor.is() )
                     throw uno::RuntimeException();
 
                 xLibraryStor = xLibrariesStor->openStorageElement( Name, embed::ElementModes::READ );
-                OSL_ENSURE( xLibraryStor.is(), "The method must either throw exception or return a storage!\n" );
+                SAL_WARN_IF(
+                    !xLibraryStor.is(), "basic",
+                    ("The method must either throw exception or return a"
+                     " storage!"));
                 if ( !xLibrariesStor.is() )
                     throw uno::RuntimeException();
             }
@@ -2339,15 +2339,11 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
             {
             #if OSL_DEBUG_LEVEL > 0
                 Any aError( ::cppu::getCaughtException() );
-                OSL_FAIL(
-                    OSL_FORMAT(
-                        ("couldn't open sub storage for library \"%s\"."
-                         " Exception: %s"),
-                        (rtl::OUStringToOString(Name, RTL_TEXTENCODING_UTF8).
-                         getStr()),
-                        rtl::OUStringToOString(
-                            comphelper::anyToString(aError),
-                            RTL_TEXTENCODING_UTF8).getStr()));
+                SAL_WARN_S(
+                    "basic",
+                    "couldn't open sub storage for library \"" << Name
+                        << "\". Exception: "
+                        << comphelper::anyToString(aError));
             #endif
                 return;
             }
@@ -2392,12 +2388,10 @@ void SAL_CALL SfxLibraryContainer::loadLibrary( const OUString& Name )
 
                 if ( !xInStream.is() )
                 {
-                    OSL_FAIL(
-                        OSL_FORMAT(
-                            ("couldn't open library element stream - attempted"
-                             " to open library \"%s\""),
-                            rtl::OUStringToOString(
-                                Name, RTL_TEXTENCODING_UTF8).getStr()));
+                    SAL_WARN_S(
+                        "basic",
+                        "couldn't open library element stream - attempted to"
+                            " open library \"" << Name << '"');
                     return;
                 }
             }
@@ -2664,7 +2658,9 @@ void SfxLibraryContainer::_disposing( const EventObject& _rSource )
 {
 #if OSL_DEBUG_LEVEL > 0
     Reference< XModel > xDocument( mxOwnerDocument.get(), UNO_QUERY );
-    OSL_ENSURE( ( xDocument == _rSource.Source ) && xDocument.is(), "SfxLibraryContainer::_disposing: where does this come from?" );
+    SAL_WARN_IF(
+        xDocument != _rSource.Source || !xDocument.is(), "basic",
+        "SfxLibraryContainer::_disposing: where does this come from?");
 #else
     (void)_rSource;
 #endif
@@ -2772,14 +2768,13 @@ OUString SfxLibraryContainer::expand_url( const OUString& url )
     {
         if( !mxMacroExpander.is() )
         {
-            Reference< XPropertySet > xProps( mxMSF, UNO_QUERY );
-            OSL_ASSERT( xProps.is() );
+            Reference< XPropertySet > xProps( mxMSF, UNO_QUERY_THROW );
             if( xProps.is() )
             {
                 Reference< XComponentContext > xContext;
                 xProps->getPropertyValue(
                     OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext;
-                OSL_ASSERT( xContext.is() );
+                SAL_WARN_IF(!xContext.is(), "basic", "no DefaultContext");
                 if( xContext.is() )
                 {
                     Reference< util::XMacroExpander > xExpander;
@@ -3085,7 +3080,9 @@ void SfxLibrary::replaceByName( const OUString& aName, const Any& aElement )
     impl_checkReadOnly();
     impl_checkLoaded();
 
-    OSL_ENSURE( isLibraryElementValid( aElement ), "SfxLibrary::replaceByName: replacing element is invalid!" );
+    SAL_WARN_IF(
+        !isLibraryElementValid(aElement), "basic",
+        "SfxLibrary::replaceByName: replacing element is invalid!");
 
     maNameContainer.replaceByName( aName, aElement );
     implSetModified( sal_True );
@@ -3099,7 +3096,9 @@ void SfxLibrary::insertByName( const OUString& aName, const Any& aElement )
     impl_checkReadOnly();
     impl_checkLoaded();
 
-    OSL_ENSURE( isLibraryElementValid( aElement ), "SfxLibrary::insertByName: to-be-inserted element is invalid!" );
+    SAL_WARN_IF(
+        !isLibraryElementValid(aElement), "basic",
+        "SfxLibrary::insertByName: to-be-inserted element is invalid!");
 
     maNameContainer.insertByName( aName, aElement );
     implSetModified( sal_True );
@@ -3226,13 +3225,12 @@ ScriptExtensionIterator::ScriptExtensionIterator( void )
     , m_pScriptSubPackageIterator( NULL )
 {
     Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
-    Reference< XPropertySet > xProps( xFactory, UNO_QUERY );
-    OSL_ASSERT( xProps.is() );
+    Reference< XPropertySet > xProps( xFactory, UNO_QUERY_THROW );
     if (xProps.is())
     {
         xProps->getPropertyValue(
             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= m_xContext;
-        OSL_ASSERT( m_xContext.is() );
+        SAL_WARN_IF(!m_xContext.is(), "basic", "no DefaultContext");
     }
     if( !m_xContext.is() )
     {
@@ -3282,7 +3280,10 @@ rtl::OUString ScriptExtensionIterator::nextBasicOrDialogLibrary( bool& rbPureDia
                 break;
             }
             case END_REACHED:
-                OSL_FAIL( "ScriptExtensionIterator::nextBasicOrDialogLibrary(): Invalid case END_REACHED" );
+                SAL_WARN(
+                    "basic",
+                    ("ScriptExtensionIterator::nextBasicOrDialogLibrary():"
+                     " Invalid case END_REACHED"));
                 break;
         }
     }
@@ -3477,7 +3478,10 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextUserScript
         {
             const Reference< deployment::XPackage >* pUserPackages = m_aUserPackagesSeq.getConstArray();
             Reference< deployment::XPackage > xPackage = pUserPackages[ m_iUserPackage ];
-            OSL_ENSURE( xPackage.is(), "ScriptExtensionIterator::implGetNextUserScriptPackage(): Invalid package" );
+            SAL_WARN_IF(
+                !xPackage.is(), "basic",
+                ("ScriptExtensionIterator::implGetNextUserScriptPackage():"
+                 " Invalid package"));
             m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
         }
 
@@ -3530,7 +3534,10 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextSharedScri
         {
             const Reference< deployment::XPackage >* pSharedPackages = m_aSharedPackagesSeq.getConstArray();
             Reference< deployment::XPackage > xPackage = pSharedPackages[ m_iSharedPackage ];
-            OSL_ENSURE( xPackage.is(), "ScriptExtensionIterator::implGetNextSharedScriptPackage(): Invalid package" );
+            SAL_WARN_IF(
+                !xPackage.is(), "basic",
+                ("ScriptExtensionIterator::implGetNextSharedScriptPackage():"
+                 " Invalid package"));
             m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
         }
 
@@ -3583,7 +3590,10 @@ Reference< deployment::XPackage > ScriptExtensionIterator::implGetNextBundledScr
         {
             const Reference< deployment::XPackage >* pBundledPackages = m_aBundledPackagesSeq.getConstArray();
             Reference< deployment::XPackage > xPackage = pBundledPackages[ m_iBundledPackage ];
-            OSL_ENSURE( xPackage.is(), "ScriptExtensionIterator::implGetNextBundledScriptPackage(): Invalid package" );
+            SAL_WARN_IF(
+                !xPackage.is(), "basic",
+                ("ScriptExtensionIterator::implGetNextBundledScriptPackage():"
+                 " Invalid package"));
             m_pScriptSubPackageIterator = new ScriptSubPackageIterator( xPackage );
         }
 
diff --git a/canvas/inc/canvas/verbosetrace.hxx b/canvas/inc/canvas/verbosetrace.hxx
index 0e83082..96e12de 100644
--- a/canvas/inc/canvas/verbosetrace.hxx
+++ b/canvas/inc/canvas/verbosetrace.hxx
@@ -29,12 +29,11 @@
 #ifndef INCLUDED_CANVAS_VERBOSETRACE_HXX
 #define INCLUDED_CANVAS_VERBOSETRACE_HXX
 
-#if OSL_DEBUG_LEVEL > 2
-/// Wrap OSL_TRACE with a verbosity switch
-#define VERBOSE_TRACE     OSL_TRACE
-#else
-#define VERBOSE_TRACE     1 ? ((void)0) : OSL_TRACE
-#endif
+#include "sal/config.h"
+
+#include "sal/log.h"
+
+#define VERBOSE_TRACE(...) SAL_INFO("canvas.level2", __VA_ARGS__)
 
 #endif /* INCLUDED_CANVAS_VERBOSETRACE_HXX */
 
diff --git a/cppu/qa/cppumaker/test_cppumaker.cxx b/cppu/qa/cppumaker/test_cppumaker.cxx
index 11435e5..bac4b16 100644
--- a/cppu/qa/cppumaker/test_cppumaker.cxx
+++ b/cppu/qa/cppumaker/test_cppumaker.cxx
@@ -372,26 +372,13 @@
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 #include <cppunit/plugin/TestPlugIn.h>
+#include "rtl/oustringostreaminserter.hxx"
 #include "rtl/ustring.h"
 #include "rtl/ustring.hxx"
 
 #include <cstddef>
 #include <iostream>
 
-//TODO, copied here from test/oustringostreaminserter.hxx, make DRY again:
-#include "osl/thread.h"
-namespace rtl {
-template< typename charT, typename traits > std::basic_ostream<charT, traits> &
-operator <<(
-    std::basic_ostream<charT, traits> & stream, rtl::OUString const & string)
-{
-    return stream <<
-        rtl::OUStringToOString(string, osl_getThreadTextEncoding()).getStr();
-        // best effort; potentially loses data due to conversion failures and
-        // embedded null characters
-}
-}
-
 namespace com { namespace sun { namespace star { namespace uno {
 
 std::ostream & operator <<(
diff --git a/cppu/qa/test_unotype.cxx b/cppu/qa/test_unotype.cxx
index dbb13d6..fa2995b 100644
--- a/cppu/qa/test_unotype.cxx
+++ b/cppu/qa/test_unotype.cxx
@@ -55,24 +55,11 @@
 #include "com/sun/star/uno/XComponentContext.hpp"
 #include "com/sun/star/uno/XInterface.hpp"
 #include "cppu/unotype.hxx"
+#include "rtl/oustringostreaminserter.hxx"
 #include "rtl/ustring.h"
 #include "rtl/ustring.hxx"
 #include "sal/types.h"
 
-//TODO, copied here from test/oustringostreaminserter.hxx, make DRY again:
-#include "osl/thread.h"
-namespace rtl {
-template< typename charT, typename traits > std::basic_ostream<charT, traits> &
-operator <<(
-    std::basic_ostream<charT, traits> & stream, rtl::OUString const & string)
-{
-    return stream <<
-        rtl::OUStringToOString(string, osl_getThreadTextEncoding()).getStr();
-        // best effort; potentially loses data due to conversion failures and
-        // embedded null characters
-}
-}
-
 namespace com { namespace sun { namespace star { namespace uno {
     class Any;
 } } } }
diff --git a/desktop/source/deployment/registry/dp_backend.cxx b/desktop/source/deployment/registry/dp_backend.cxx
index 672364d..e847c3c 100644
--- a/desktop/source/deployment/registry/dp_backend.cxx
+++ b/desktop/source/deployment/registry/dp_backend.cxx
@@ -31,8 +31,10 @@
 
 #include "dp_backend.h"
 #include "dp_ucb.h"
+#include "rtl/oustringostreaminserter.hxx"
 #include "rtl/uri.hxx"
 #include "rtl/bootstrap.hxx"
+#include "sal/log.h"
 #include "osl/file.hxx"
 #include "cppuhelper/exc_hlp.hxx"
 #include "comphelper/servicedecl.hxx"
@@ -73,7 +75,7 @@ void PackageRegistryBackend::disposing( lang::EventObject const & event )
     ::osl::MutexGuard guard( getMutex() );
     if ( m_bound.erase( url ) != 1 )
     {
-        OSL_ASSERT( false );
+        SAL_WARN_S("basic", "erase(" << url << ") != 1");
     }
 }
 
@@ -207,8 +209,9 @@ Reference<deployment::XPackage> PackageRegistryBackend::bindPackage(
         m_bound.insert( t_string2ref::value_type( url, xNewPackage ) ) );
     if (insertion.second)
     { // first insertion
-        OSL_ASSERT( Reference<XInterface>(insertion.first->second)
-                    == xNewPackage );
+        SAL_WARN_IF(
+            Reference<XInterface>(insertion.first->second) != xNewPackage,
+            "desktop", "mismatch");
     }
     else
     { // found existing entry
@@ -339,7 +342,7 @@ Package::Package( ::rtl::Reference<PackageRegistryBackend> const & myBackend,
     if (m_bRemoved)
     {
         //We use the last segment of the URL
-        OSL_ASSERT(m_name.getLength() == 0);
+        SAL_WARN_IF(!m_name.isEmpty(), "basic", "non-empty m_name");
         OUString name = m_url;
         rtl::Bootstrap::expandMacros(name);
         sal_Int32 index = name.lastIndexOf('/');
@@ -679,11 +682,8 @@ void Package::processPackage_impl(
         }
         catch (RuntimeException &e) {
             (void) e; // avoid warnings
-            OSL_FAIL(
-                OSL_FORMAT(
-                    "unexpected RuntimeException \"%s\"",
-                    (rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8).
-                     getStr())));
+            SAL_WARN_S(
+                "basic", "unexpected RuntimeException \"" << e.Message << '"');
             throw;
         }
         catch (CommandFailedException &) {
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h
index 6a8ef32..eb1cd03 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h
+++ b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h
@@ -25,98 +25,20 @@
  * for a copy of the LGPLv3 License.
  *
  ************************************************************************/
-#if !defined INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
-#define INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
-#include "osl/diagnose.h"
-#include "rtl/ustring.hxx"
-#include <stdio.h>
-
-#if OSL_DEBUG_LEVEL >= 1
-#define JFW_ENSURE(c, m)  _JFW_ENSURE(c, OSL_THIS_FILE, __LINE__,  m)
-#else
-#define JFW_ENSURE(c, m)  ((void) 0)
-#endif
-
-#if OSL_DEBUG_LEVEL >= 2
-#define JFW_WARNING2(c, m)  _JFW_WARNING2(c, OSL_THIS_FILE, __LINE__, m)
-#else
-#define JFW_WARNING2(c, m)  ((void) 0)
-#endif
-
-
-#if OSL_DEBUG_LEVEL >= 0
-#define JFW_TRACE0(m)  jfw_trace(m)
-#else
-#define JFW_TRACE0(m)  ((void) 0)
-#endif
-
-#if OSL_DEBUG_LEVEL >= 1
-#define JFW_TRACE1(m)  jfw_trace(m)
-#else
-#define JFW_TRACE1(m)  ((void) 0)
-#endif
-
-#if OSL_DEBUG_LEVEL >= 2
-#define JFW_TRACE2(m)  jfw_trace(m)
-#else
-#define JFW_TRACE2(m)  ((void) 0)
-#endif
-
-
 
-#define _JFW_ENSURE(c, f, l, m)  jfw_ensure(c, f, l, m)
-#define _JFW_WARNING(c, f, l, m)  jfw_warning2(c, f, l, m);
-
-
-namespace jfw_plugin
-{
-
-inline void jfw_ensure(bool
-                       #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
-                       condition
-                       #endif
-                       , const sal_Char *
-                       #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
-                       pzFile
-                       #endif
-                       , sal_Int32
-                       #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
-                       line
-                       #endif
-                       , const rtl::OUString& message )
-{
-    rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding());
-    _OSL_ENSURE(condition, pzFile, line, oMsg.getStr());
-}
+#ifndef INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
+#define INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
 
-inline void jfw_warning2(bool condition, const sal_Char * pzFile, sal_Int32 line,
-                         sal_Char * pzMessage)
-{
-    if (! condition)
-        fprintf(
-            stderr, "%s\n File: %s\n Line: %ld", pzMessage, pzFile,
-            sal::static_int_cast< unsigned long >(line));
-}
+#include "sal/config.h"
 
-inline void jfw_trace(rtl::OUString message)
-{
-    rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding());
-    fprintf(stderr,"%s", oMsg.getStr());
-}
+#include "rtl/oustringostreaminserter.hxx"
+#include "sal/log.h"
 
-inline void jfw_trace(const sal_Char * pzMessage)
-{
-    if (pzMessage)
-        fprintf(stderr,"%s", pzMessage);
-}
+#define JFW_ENSURE(c, m) SAL_WARN_IF_S(!(c), "jfw", m)
 
-inline void jfw_trace(const rtl::OString& message)
-{
-    if (message.getLength() > 0)
-        fprintf(stderr,"%s", message.getStr());
-}
+#define JFW_TRACE0(m) SAL_INFO_S("jfw.level1", m)
 
-}
+#define JFW_TRACE2(m) SAL_INFO_S("jfw.level2", m);
 
 #endif
 
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
index 00843ec..1b2dd23 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx
@@ -70,7 +70,6 @@ using ::rtl::OString;
 using ::rtl::OUStringBuffer;
 using ::rtl::OUStringToOString;
 
-#define CHAR_POINTER(oustr) ::rtl::OUStringToOString(oustr,RTL_TEXTENCODING_UTF8).pData->buffer
 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
 #ifdef WNT
 #define HKEY_SUN_JRE L"Software\\JavaSoft\\Java Runtime Environment"
@@ -310,14 +309,13 @@ class AsynchReader: public Thread
 public:
 
     AsynchReader(oslFileHandle & rHandle);
-#if OSL_DEBUG_LEVEL >= 2
+
     /** only call this function after this thread has finished.
 
         That is, call join on this instance and then call getData.
 
      */
     OString getData();
-#endif
 };
 
 AsynchReader::AsynchReader(oslFileHandle & rHandle):
@@ -325,13 +323,11 @@ AsynchReader::AsynchReader(oslFileHandle & rHandle):
 {
 }
 
-#if OSL_DEBUG_LEVEL >= 2
 OString AsynchReader::getData()
 {
     OSL_ASSERT(isRunning() == sal_False );
     return OString(m_arData.get(), m_nDataSize);
 }
-#endif
 
 void AsynchReader::run()
 {
@@ -469,8 +465,7 @@ bool getJavaProps(const OUString & exePath,
         OUString sLine;
         if (!decodeOutput(aLine, &sLine))
             continue;
-        JFW_TRACE2(OString("[Java framework]:\" ")
-               + OString( CHAR_POINTER(sLine)) + OString(" \".\n"));
+        JFW_TRACE2("[Java framework]:\" " << sLine << " \".\n");
         sLine = sLine.trim();
         if (sLine.getLength() == 0)
             continue;
@@ -497,8 +492,8 @@ bool getJavaProps(const OUString & exePath,
 
     //process error stream data
     stderrReader.join();
-    JFW_TRACE2(OString("[Java framework]  Java wrote to stderr:\" ")
-               + stderrReader.getData() + OString(" \".\n"));
+    JFW_TRACE2("[Java framework]  Java wrote to stderr:\" "
+               << stderrReader.getData().getStr() << " \".\n");
 
     TimeValue waitMax= {5 ,0};
     procErr = osl_joinProcessWithTimeout(javaProcess, &waitMax);
diff --git a/sal/inc/osl/diagnose.h b/sal/inc/osl/diagnose.h
index aab76b3..8e889ac 100644
--- a/sal/inc/osl/diagnose.h
+++ b/sal/inc/osl/diagnose.h
@@ -30,10 +30,25 @@
 #ifndef _OSL_DIAGNOSE_H_
 #define _OSL_DIAGNOSE_H_
 
+#include "sal/config.h"
+
+#include <sal/log.h>
 #include <sal/types.h>
 
 /** provides simple diagnostic support
 
+    The facilities provided by this header are deprecated.  True assertions
+    (that detect broken program logic) should use standard assert (which aborts
+    if an assertion fails, and is controlled by the standard NDEBUG macro).
+    Logging of warnings (e.g., about malformed input) and traces (e.g., about
+    steps taken while executing some protocol) should use the facilities
+    provided by sal/log.h.
+
+    Because the assertion macros (OSL_ASSERT, OSL_ENSURE, OSL_FAIL, OSL_PRECOND,
+    and OSL_POSTCOND) have been used for true assertions as well as for logged
+    warnings, they map to SAL_WARN instead of standard assert.  OSL_TRACE maps
+    to SAL_INFO.
+
     The functions defined in this header are not intended to be used directly,
     but through defined macros. The macros can be divided into three categories:
     assertions, traces and other stuff .-) Their usability depends on the value
@@ -122,14 +137,25 @@ pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pf
 
 #define OSL_THIS_FILE       __FILE__
 
-/* the macro OSL_LOG_PREFIX is intended to be an office internal macro for now */
-#define OSL_LOG_PREFIX OSL_THIS_FILE ":" SAL_STRINGIFY( __LINE__ ) "; "
+/* the macro OSL_LOG_PREFIX is intended to be an office internal macro for now
+
+   it is deprecated and superseded by SAL_WHERE
+*/
+#define OSL_LOG_PREFIX SAL_WHERE
 
 #define OSL_DEBUG_ONLY(s)   _OSL_DEBUG_ONLY(s)
-#define OSL_TRACE           _OSL_TRACE
-#define OSL_ASSERT(c)       _OSL_ENSURE(c, OSL_THIS_FILE, __LINE__, 0)
-#define OSL_ENSURE(c, m)   _OSL_ENSURE(c, OSL_THIS_FILE, __LINE__, m)
-#define OSL_FAIL(m)        _OSL_ENSURE(0, OSL_THIS_FILE, __LINE__, m)
+
+#if OSL_DEBUG_LEVEL > 0
+#define OSL_TRACE(...) SAL_INFO("legacy.osl", __VA_ARGS__)
+#define OSL_ASSERT(c) SAL_WARN_IF(!(c), "legacy.osl", "OSL_ASSERT")
+#define OSL_ENSURE(c, m) SAL_WARN_IF(!(c), "legacy.osl", "%s", m)
+#define OSL_FAIL(m) SAL_WARN_IF(sal_True, "legacy.osl", "%s", m)
+#else
+#define OSL_TRACE(...) ((void) 0)
+#define OSL_ASSERT(c) ((void) 0)
+#define OSL_ENSURE(c, m) ((void) 0)
+#define OSL_FAIL(m) ((void) 0)
+#endif
 
 #define OSL_VERIFY(c) do { if (!(c)) OSL_ASSERT(0); } while (0)
 #define OSL_PRECOND(c, m)   OSL_ENSURE(c, m)
@@ -145,27 +171,10 @@ pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pf
 #if OSL_DEBUG_LEVEL > 0
 
 #define _OSL_DEBUG_ONLY(f)  (f)
-#define _OSL_ENSURE(c, f, l, m) \
-    do \
-    {  \
-        if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, m)) \
-            _OSL_GLOBAL osl_breakDebug(); \
-    } while (0)
 
 #else
 
 #define _OSL_DEBUG_ONLY(f)          ((void)0)
-#define _OSL_ENSURE(c, f, l, m)     ((void)0)
-
-#endif /* OSL_DEBUG_LEVEL */
-
-#if OSL_DEBUG_LEVEL > 1
-
-#define _OSL_TRACE                  _OSL_GLOBAL osl_trace
-
-#else
-
-#define _OSL_TRACE                  1 ? ((void)0) : _OSL_GLOBAL osl_trace
 
 #endif /* OSL_DEBUG_LEVEL */
 
@@ -192,30 +201,6 @@ pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pf
 #define OSL_THIS_FUNC ""
 #endif
 
-#if defined __cplusplus
-
-#include "rtl/string.hxx"
-
-/** @internal */
-extern "C" struct _rtl_String * SAL_CALL osl_detail_formatString(
-    char const * format, ...) SAL_THROW_EXTERN_C();
-    // "struct _rtl_String" instead of "rtl_String" for the case where
-    // osl/diagnose.h is included in rtl/string.hxx
-
-/** A facility for printf-style messages in OSL_ENSURE, OSL_FAIL, etc.
-
-    Use like: OSL_ENSURE(i == 5, OSL_FORMAT("i should be 5 but is %d", i));
-*/
-#define OSL_FORMAT(format, ...) \
-    (::rtl::OString( \
-        ::osl_detail_formatString(format, __VA_ARGS__), \
-        ::SAL_NO_ACQUIRE).getStr())
-    // it appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
-    // Express) already support variadic macros in C++; see also
-    // <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>
-
-#endif
-
 #endif /* _OSL_DIAGNOSE_H_ */
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/inc/osl/diagnose.hxx b/sal/inc/osl/diagnose.hxx
index a9aba13..42e4b8d 100644
--- a/sal/inc/osl/diagnose.hxx
+++ b/sal/inc/osl/diagnose.hxx
@@ -25,27 +25,22 @@
  * for a copy of the LGPLv3 License.
  *
  ************************************************************************/
-#if ! defined(OSL_DIAGNOSE_HXX_INCLUDED)
+#ifndef OSL_DIAGNOSE_HXX_INCLUDED
 #define OSL_DIAGNOSE_HXX_INCLUDED
 
-#if ! defined(_OSL_DIAGNOSE_H_)
+#include "sal/config.h"
+
+#include <functional>
+#include <typeinfo>
+
+#include "boost/unordered_set.hpp"
 #include "osl/diagnose.h"
-#endif
-#if ! defined(_OSL_INTERLOCK_H_)
 #include "osl/interlck.h"
-#endif
-#if ! defined(_OSL_MUTEX_HXX_)
 #include "osl/mutex.hxx"
-#endif
-#if ! defined(INCLUDED_RTL_ALLOCATOR_HXX)
 #include "rtl/allocator.hxx"
-#endif
-#if ! defined(_RTL_INSTANCE_HXX_)
 #include "rtl/instance.hxx"
-#endif
-#include <boost/unordered_set.hpp>
-#include <functional>
-#include <typeinfo>
+#include "sal/log.h"
+#include "sal/types.h"
 
 namespace osl {
 /// @internal
@@ -126,7 +121,7 @@ public:
             VoidPointerSet::const_iterator iPos(m_data.m_addresses.begin());
             VoidPointerSet::const_iterator const iEnd(m_data.m_addresses.end());
             for ( ; iPos != iEnd; ++iPos ) {
-                OSL_ASSERT( *iPos != 0 );
+                SAL_WARN_IF( *iPos == 0, "sal.debug", "null pointer" );
             }
         }
         return bRet;
@@ -179,7 +174,7 @@ public:
     static bool checkObjectCount( ::std::size_t = 0 ) { return true; }
 #else // OSL_DEBUG_LEVEL > 0
     /** @return whether the expected number of objects is alive,
-                else this function OSL_ASSERTs
+                else this function SAL_WARNs
     */
     static bool checkObjectCount( ::std::size_t nExpected = 0 ) {
         return StaticObjectRegistry::get().checkObjectCount(nExpected);
diff --git a/sal/inc/osl/thread.hxx b/sal/inc/osl/thread.hxx
index 2bcc82f..2916ff7 100644
--- a/sal/inc/osl/thread.hxx
+++ b/sal/inc/osl/thread.hxx
@@ -29,7 +29,9 @@
 #ifndef _THREAD_HXX_
 #define _THREAD_HXX_
 
-#ifdef __cplusplus
+#include "sal/config.h"
+
+#include <cassert>
 
 #include <osl/time.h>
 
@@ -71,7 +73,7 @@ public:
 
     sal_Bool SAL_CALL create()
     {
-        OSL_ASSERT(m_hThread == 0); // only one running thread per instance
+        assert(m_hThread == 0); // only one running thread per instance
            if (m_hThread)
             return sal_False;
 
@@ -84,7 +86,7 @@ public:
 
     sal_Bool SAL_CALL createSuspended()
     {
-        OSL_ASSERT(m_hThread == 0); // only one running thread per instance
+        assert(m_hThread == 0); // only one running thread per instance
         if( m_hThread)
             return sal_False;
         m_hThread= osl_createSuspendedThread( threadFunc,
@@ -233,7 +235,7 @@ private:
 };
 
 } // end namespace osl
-#endif
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/inc/rtl/oustringostreaminserter.hxx b/sal/inc/rtl/oustringostreaminserter.hxx
new file mode 100644
index 0000000..579ffa0
--- /dev/null
+++ b/sal/inc/rtl/oustringostreaminserter.hxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org.  If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#ifndef INCLUDED_RTL_OUSTRINGOSTREAMINSERTER_HXX
+#define INCLUDED_RTL_OUSTRINGOSTREAMINSERTER_HXX
+
+#include "sal/config.h"
+
+#include <ostream>
+
+#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.
+*/
+
+namespace rtl {
+
+template< typename charT, typename traits > std::basic_ostream<charT, traits> &
+operator <<(
+    std::basic_ostream<charT, traits> & stream, rtl::OUString const & string)
+{
+    return stream <<
+        rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr();
+        // best effort; potentially loses data due to conversion failures
+        // (stray surrogate halves) and embedded null characters
+}
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/inc/rtl/strbuf.hxx b/sal/inc/rtl/strbuf.hxx
index 962d3df..5f0b9b3 100644
--- a/sal/inc/rtl/strbuf.hxx
+++ b/sal/inc/rtl/strbuf.hxx
@@ -29,7 +29,10 @@
 #ifndef _RTL_STRBUF_HXX_
 #define _RTL_STRBUF_HXX_
 
-#include "osl/diagnose.h"
+#include "sal/config.h"
+
+#include <cassert>
+
 #include <rtl/strbuf.h>
 #include <rtl/string.hxx>
 
@@ -253,7 +256,7 @@ public:
      */
     void setLength(sal_Int32 newLength)
     {
-        OSL_ASSERT(newLength >= 0);
+        assert(newLength >= 0);
         // Avoid modifications if pData points to const empty string:
         if( newLength != pData->length )
         {
@@ -280,7 +283,7 @@ public:
      */
     sal_Char charAt( sal_Int32 index )
     {
-        OSL_ASSERT(index >= 0 && index < pData->length);
+        assert(index >= 0 && index < pData->length);
         return pData->buffer[ index ];
     }
 
@@ -321,7 +324,7 @@ public:
      */
     OStringBuffer & setCharAt(sal_Int32 index, sal_Char ch)
     {
-        OSL_ASSERT(index >= 0 && index < pData->length);
+        assert(index >= 0 && index < pData->length);
         pData->buffer[ index ] = ch;
         return *this;
     }
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index ee41011..007129a 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -29,12 +29,15 @@
 #ifndef _RTL_STRING_HXX_
 #define _RTL_STRING_HXX_
 
-#ifdef __cplusplus
+#include "sal/config.h"
+
+#include <cassert>
 
 #include <osl/diagnose.h>
 #include <rtl/memory.h>
 #include <rtl/textenc.h>
 #include <rtl/string.h>
+#include "sal/log.h"
 
 #if !defined EXCEPTIONS_OFF
 #include <new>
@@ -183,13 +186,13 @@ public:
     {
         pData = 0;
         rtl_uString2String( &pData, value, length, encoding, convertFlags );
+        if (pData == 0) {
 #if defined EXCEPTIONS_OFF
-        OSL_ASSERT(pData != NULL);
+            SAL_WARN("sal", "std::bad_alloc but EXCEPTIONS_OFF");
 #else
-        if (pData == 0) {
             throw std::bad_alloc();
-        }
 #endif
+        }
     }
 
     /**
@@ -655,7 +658,7 @@ public:
     */
     OString copy( sal_Int32 beginIndex ) const SAL_THROW(())
     {
-        OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength());
+        assert(beginIndex >= 0 && beginIndex <= getLength());
         if ( beginIndex == 0 )
             return *this;
         else
@@ -679,8 +682,8 @@ public:
     */
     OString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
     {
-        OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength()
-                   && count >= 0 && count <= getLength() - beginIndex);
+        assert(beginIndex >= 0 && beginIndex <= getLength()
+               && count >= 0 && count <= getLength() - beginIndex);
         if ( (beginIndex == 0) && (count == getLength()) )
             return *this;
         else
@@ -1034,8 +1037,6 @@ struct OStringHash
 
 } /* Namespace */
 
-#endif /* __cplusplus */
-
 #endif /* _RTL_STRING_HXX_ */
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index 60bb750..2456316 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -29,12 +29,14 @@
 #ifndef _RTL_USTRBUF_HXX_
 #define _RTL_USTRBUF_HXX_
 
+#include "sal/config.h"
+
+#include <cassert>
+
 #include <osl/diagnose.h>
 #include <rtl/ustrbuf.h>
 #include <rtl/ustring.hxx>
 
-#ifdef __cplusplus
-
 namespace rtl
 {
 
@@ -233,7 +235,7 @@ public:
      */
     void setLength(sal_Int32 newLength)
     {
-        OSL_ASSERT(newLength >= 0);
+        assert(newLength >= 0);
         // Avoid modifications if pData points to const empty string:
         if( newLength != pData->length )
         {
@@ -260,7 +262,7 @@ public:
      */
     sal_Unicode charAt( sal_Int32 index ) const
     {
-        OSL_ASSERT(index >= 0 && index < pData->length);
+        assert(index >= 0 && index < pData->length);
         return pData->buffer[ index ];
     }
 
@@ -301,7 +303,7 @@ public:
      */
     OUStringBuffer & setCharAt(sal_Int32 index, sal_Unicode ch)
     {
-        OSL_ASSERT(index >= 0 && index < pData->length);
+        assert(index >= 0 && index < pData->length);
         pData->buffer[ index ] = ch;
         return *this;
     }
@@ -434,7 +436,7 @@ public:
      */
     OUStringBuffer & append(char c)
     {
-        OSL_ASSERT(static_cast< unsigned char >(c) <= 0x7F);
+        assert(static_cast< unsigned char >(c) <= 0x7F);
         return append(sal_Unicode(c));
     }
 
@@ -819,7 +821,6 @@ private:
 
 }
 
-#endif  /* __cplusplus */
 #endif  /* _RTL_USTRBUF_HXX_ */
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index edf7c97..ef13dd1 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -29,12 +29,15 @@
 #ifndef _RTL_USTRING_HXX_
 #define _RTL_USTRING_HXX_
 
-#ifdef __cplusplus
+#include "sal/config.h"
+
+#include <cassert>
 
 #include "osl/diagnose.h"
 #include <rtl/ustring.h>
 #include <rtl/string.hxx>
 #include <rtl/memory.h>
+#include "sal/log.h"
 
 #if defined EXCEPTIONS_OFF
 #include <stdlib.h>
@@ -184,13 +187,13 @@ public:
     {
         pData = 0;
         rtl_string2UString( &pData, value, length, encoding, convertFlags );
+        if (pData == 0) {
 #if defined EXCEPTIONS_OFF
-        OSL_ASSERT(pData != NULL);
+            SAL_WARN("sal", "std::bad_alloc but EXCEPTIONS_OFF");
 #else
-        if (pData == 0) {
             throw std::bad_alloc();
-        }
 #endif
+        }
     }
 
     /** Create a new string from an array of Unicode code points.
@@ -967,7 +970,7 @@ public:
     */
     OUString copy( sal_Int32 beginIndex ) const SAL_THROW(())
     {
-        OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength());
+        assert(beginIndex >= 0 && beginIndex <= getLength());
         if ( beginIndex == 0 )
             return *this;
         else
@@ -991,7 +994,7 @@ public:
     */
     OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const SAL_THROW(())
     {
-        OSL_ASSERT(beginIndex >= 0 && beginIndex <= getLength() && count >= 0);
+        assert(beginIndex >= 0 && beginIndex <= getLength() && count >= 0);
         if ( (beginIndex == 0) && (count == getLength()) )
             return *this;
         else
@@ -1243,13 +1246,13 @@ public:
     {
         rtl_uString * pNew = 0;
         rtl_uString_intern( &pNew, pData );
+        if (pNew == 0) {
 #if defined EXCEPTIONS_OFF
-        OSL_ASSERT(pNew != NULL);
+            SAL_WARN("sal", "std::bad_alloc but EXCEPTIONS_OFF");
 #else
-        if (pNew == 0) {
             throw std::bad_alloc();
-        }
 #endif
+        }
         return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
     }
 
@@ -1286,13 +1289,13 @@ public:
         rtl_uString * pNew = 0;
         rtl_uString_internConvert( &pNew, value, length, encoding,
                                    convertFlags, pInfo );
+        if (pNew == 0) {
 #if defined EXCEPTIONS_OFF
-        OSL_ASSERT(pNew != NULL);
+            SAL_WARN("sal", "std::bad_alloc but EXCEPTIONS_OFF");
 #else
-        if (pNew == 0) {
             throw std::bad_alloc();
-        }
 #endif
+        }
         return OUString( pNew, (DO_NOT_ACQUIRE *)0 );
     }
 
@@ -1576,8 +1579,6 @@ inline OString OUStringToOString( const OUString & rUnicode,
 
 } /* Namespace */
 
-#endif /* __cplusplus */
-
 #endif /* _RTL_USTRING_HXX */
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/inc/sal/log.h b/sal/inc/sal/log.h
new file mode 100644
index 0000000..9e15560
--- /dev/null
+++ b/sal/inc/sal/log.h
@@ -0,0 +1,305 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * [ Copyright (C) 2011 Stephan Bergmann, Red Hat <sbergman at redhat.com> (initial
+ *   developer) ]
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef INCLUDED_SAL_LOG_H
+#define INCLUDED_SAL_LOG_H
+
+#include "sal/config.h"
+
+#if defined __cplusplus
+#include <sstream>
+#include <string>
+#endif
+
+#include "sal/types.h"
+
+/* This header uses variadic macros in both C (where they are officially only
+   supported since C99) and C++ (where they are officially only supported since
+   C++11).  It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
+   Express) already support them in their C and C++ dialects.  See also
+   <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>.
+
+   Avoid the use of other sal code in this header as much as possible, so that
+   this code can be called from other sal code without causing endless
+   recursion.
+*/
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+/** @internal */
+enum sal_detail_LogLevel {
+    SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
+    SAL_DETAIL_MAKE_FIXED_SIZE = SAL_MAX_ENUM
+};
+
+/** @internal */
+void SAL_CALL sal_detail_log(
+    enum sal_detail_LogLevel level, char const * area, char const * where,
+    char const * message);
+
+/** @internal */
+void SAL_CALL sal_detail_logFormat(
+    enum sal_detail_LogLevel level, char const * area, char const * where,
+    char const * format, ...)
+/* TODO: enabling this will produce a huge amount of -Werror=format errors: */
+#if defined GCC && 0
+    __attribute__((format(printf, 4, 5)))
+#endif
+    ;
+
+#if defined __cplusplus
+}
+#endif
+
+/** @internal */
+#define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \
+    do { \
+        if (condition) { \
+            sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \
+        } \
+    } while (sal_False)
+
+#if defined __cplusplus
+
+namespace sal { namespace detail {
+
+/// @internal
+inline void SAL_CALL log(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    std::ostringstream const & stream)
+{
+    // An alternative would be to have sal_detail_log take a std::ostringstream
+    // pointer (via a C void pointer); the advantage would be smaller client
+    // code (the ".str().c_str()" part would move into the implementation of
+    // sal_detail_log) and potential for proper support of embedded null
+    // characters within the message, but the disadvantage would be dependence
+    // on the C++ ABI; as a compromise, the ".str().c_str()" part has been moved
+    // to this inline function so that it is potentially only emitted once per
+    // dynamic library:
+    sal_detail_log(level, area, where, stream.str().c_str());
+}
+
+} }
+
+/// @internal
+#define SAL_DETAIL_LOG_STREAM(condition, level, area, where, stream) \
+    do { \
+        if (condition) { \
+            ::std::ostringstream sal_detail_stream; \
+            sal_detail_stream << stream; \
+            ::sal::detail::log((level), (area), (where), sal_detail_stream); \
+        } \
+    } while (false)
+
+#endif
+
+/** A simple macro to create a "file and line number" string.
+
+    Potentially not only useful within the log framework (where it is used
+    automatically), but also when creating exception messages.
+
+    @since LibreOffice 3.5
+*/
+#define SAL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": "
+
+#if defined __cplusplus
+
+/** A facility for generating temporary string messages by piping items into a
+    C++ std::ostringstream.
+
+    This can be useful for example in a call to SAL_INFO_S when depending on
+    some boolean condition data of incompatible types shall be streamed into the
+    message, as in:
+
+      SAL_INFO_S(
+        "foo", "object: " << (hasName ? obj->name : SAL_STREAM(obj)));
+
+    @since LibreOffice 3.5
+*/
+#define SAL_STREAM(stream) \
+    (dynamic_cast< ::std::ostringstream & >(::std::ostringstream() << stream). \
+     str())
+
+#endif
+
+/** Basic logging functionality.
+
+    SAL_INFO(char const * area, char const * format, ...),
+    SAL_INFO_IF(bool condition, char const * area, char const * format, ...),
+    SAL_WARN(char const * area, char const * format, ...), and
+    SAL_WARN_IF(bool condition, char const * area, char const * format, ...)
+    produce an info resp. warning log entry with a printf-style message.  The
+    given format argument and any following arguments must be so that that
+    sequence of arguments would be appropriate for a call to printf.
+
+    SAL_INFO_S(char const * area, expr),
+    SAL_INFO_IF_S(bool condition, char const * area, expr),
+    SAL_WARN_S(char const * area, expr), and
+    SAL_WARN_IF_S(bool condition, char const * area, expr) produce an info resp.
+    warning log entry with a message produced by piping items into a C++
+    std::ostringstream (and are only available in C++).  The given expr must be
+    so that the full expression "stream << expr" is valid, where stream is a
+    variable of type std::ostringstream.
+
+      SAL_INFO_S("foo", "string " << s << " of length " << n)
+
+    would be an example of such a call; if the given s is of type rtl::OUString,
+
+      #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
+    contain no vertical formatting characters and no null characters
+
+    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
+    match the regular expression
+
+      <area> ::= <segment>("."<segment>)*
+
+    with
+
+      <segment> ::= [0-9a-z]+
+
+    Whether these macros generate any log output is controlled in a two-stage
+    process.
+
+    First, at compile time the macros SAL_LOG_INFO and SAL_LOG_WARN,
+    respectively, control whether the INFO and WARN macros, respectively,
+    expand to actual code (in case the macro is defined, to any value) or to
+    no-ops (in case the macro is not defined).
+
+    Second, at runtime the environment variable SAL_LOG further limits which
+    macro calls actually generate log output.  The environment variable SAL_LOG
+    must either be unset or must match the regular expression
+
+      <env> ::= <switch>*
+
+    with
+
+      <switch> ::= <sense><level>("."<area>)?
+      <sense> ::= "+"|"-"
+      <level> ::= "INFO"|"WARN"
+
+    If the environment variable is unset, "+WARN" is used instead (which results
+    in all warnings being output but no infos).  If the given value does not
+    match the regular expression, "+INFO+WARN" is used instead (which in turn
+    results in everything being output).
+
+    A given macro call's level (INFO or WARN) and area is matched against the
+    given switches as follows:  Only those switches for which the level matches
+    the given level and for which the area is a prefix (including both empty and
+    full prefixes) of the given area are considered.  Log output is generated if
+    and only if among the longest such switches (if any), there is at least one
+    that has a sense of "+".  (That is, if both +INFO.foo and -INFO.foo are
+    present, +INFO.foo wins.)
+
+    For example, if SAL_LOG is "+INFO-INFO.foo+INFO.foo.bar", then calls like
+    SAL_INFO("foo.bar", ...), SAL_INFO("foo.bar.baz", ...), or
+    SAL_INFO("other", ...) generate output, while calls like
+    SAL_INFO("foo", ...) or SAL_INFO("foo.barzzz", ...) do not.
+
+    The generated log output consists of the given level ("info" or "warn"), the
+    given area, the process ID, the thread ID, the source file, and the source
+    line number, each followed by a colon, followed by a space, the given
+    message, and a newline.  The precise format of the log output is subject to
+    change.  The log output is printed to stderr without further text encoding
+    conversion.
+
+    @since LibreOffice 3.5
+*/
+
+#if defined SAL_LOG_INFO
+
+#define SAL_INFO(area, ...) \
+    SAL_DETAIL_LOG_FORMAT( \
+        sal_True, SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, __VA_ARGS__)
+#define SAL_INFO_IF(condition, area, ...) \
+    SAL_DETAIL_LOG_FORMAT( \
+        condition, SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, __VA_ARGS__)
+
+#if defined __cplusplus
+#define SAL_INFO_S(area, stream) \
+    SAL_DETAIL_LOG_STREAM( \
+        true, ::SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, stream)
+#define SAL_INFO_IF_S(condition, area, stream)  \
+    SAL_DETAIL_LOG_STREAM( \
+        condition, ::SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, stream)
+#endif
+
+#else
+
+#define SAL_INFO(area, format, ...) ((void) 0)
+#define SAL_INFO_IF(condition, area, format, ...) ((void) 0)
+
+#if defined __cplusplus
+#define SAL_INFO_S(area, stream) ((void) 0)
+#define SAL_INFO_IF_S(condition, area, stream) ((void) 0)
+#endif
+
+#endif
+
+#if defined SAL_LOG_WARN
+
+#define SAL_WARN(area, ...) \
+    SAL_DETAIL_LOG_FORMAT( \
+        sal_True, SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, __VA_ARGS__)
+#define SAL_WARN_IF(condition, area, ...) \
+    SAL_DETAIL_LOG_FORMAT( \
+        condition, SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, __VA_ARGS__)
+
+#if defined __cplusplus
+#define SAL_WARN_S(area, stream) \
+    SAL_DETAIL_LOG_STREAM( \
+        true, ::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream)
+#define SAL_WARN_IF_S(condition, area, stream)   \
+    SAL_DETAIL_LOG_STREAM( \
+        condition, ::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream)
+#endif
+
+#else
+
+#define SAL_WARN(area, format, ...) ((void) 0)
+#define SAL_WARN_IF(condition, area, format, ...) ((void) 0)
+
+#if defined __cplusplus
+#define SAL_WARN_S(area, stream) ((void) 0)
+#define SAL_WARN_IF_S(condition, area, stream) ((void) 0)
+#endif
+
+#endif
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/all/formatstring.cxx b/sal/osl/all/formatstring.cxx
deleted file mode 100644
index 9fefa2f..0000000
--- a/sal/osl/all/formatstring.cxx
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Version: MPL 1.1 / GPLv3+ / LGPLv3+
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License or as specified alternatively below. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Major Contributor(s):
- * [ Copyright (C) 2011 Stephan Bergmann, Red Hat Inc. <sbergman at redhat.com>
- *   (initial developer) ]
- *
- * All Rights Reserved.
- *
- * For minor contributions see the git repository.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
- * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
- * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
- * instead of those above.
- */
-
-#include "precompiled_sal.hxx"
-#include "sal/config.h"
-
-#include <cstdarg>
-#include <cstring>
-#include <stdio.h> // vsnprintf not in C++03 <cstdio>, only C99 <stdio.h>
-
-#include "osl/diagnose.h"
-#include "rtl/string.h"
-#include "rtl/string.hxx"
-
-rtl_String * osl_detail_formatString(char const * format, ...)
-    SAL_THROW_EXTERN_C()
-{
-    // Avoid the use of other sal code as much as possible, so that this code
-    // can be called from other sal code without causing endless recursion:
-    char buf[1024];
-    int n1 = sizeof buf - RTL_CONSTASCII_LENGTH("...");
-    std::va_list args;
-    va_start(args, format);
-    int n2 = vsnprintf(buf, n1, format, args);
-    va_end(args);
-    if (n2 < 0) {
-        std::strcpy(buf, "???");
-        n2 = RTL_CONSTASCII_LENGTH("???");
-    } else if (n2 >= n1) {
-        std::strcpy(buf + n1 - 1, "...");
-        n2 = sizeof buf - 1;
-    }
-    rtl::OString s(buf, n2);
-    rtl_string_acquire(s.pData);
-    return s.pData;
-}
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
new file mode 100644
index 0000000..be45cf6
--- /dev/null
+++ b/sal/osl/all/log.cxx
@@ -0,0 +1,199 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * [ Copyright (C) 2011 Stephan Bergmann, Red Hat <sbergman at redhat.com> (initial
+ *   developer) ]
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "precompiled_sal.hxx"
+#include "sal/config.h"
+
+#include <cassert>
+#include <cstdarg>
+#include <cstddef>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <sstream>
+
+#include <stdio.h> // vsnprintf
+
+#include "osl/thread.hxx"
+#include "rtl/string.h"
+#include "sal/log.h"
+#include "sal/types.h"
+
+#include "logformat.hxx"
+
+#if defined WNT
+#include <process.h>
+#define OSL_DETAIL_GETPID _getpid()
+#else
+#include <unistd.h>
+#define OSL_DETAIL_GETPID getpid()
+#endif
+
+// Avoid the use of other sal code in this file as much as possible, so that
+// this code can be called from other sal code without causing endless
+// recursion.
+
+namespace {
+
+bool equalStrings(
+    char const * string1, std::size_t length1, char const * string2,
+    std::size_t length2)
+{
+    return length1 == length2 && std::memcmp(string1, string2, length1) == 0;
+}
+
+char const * toString(sal_detail_LogLevel level) {
+    switch (level) {
+    default:
+        assert(false); // this cannot happen
+        // fall through
+    case SAL_DETAIL_LOG_LEVEL_INFO:
+        return "info";
+    case SAL_DETAIL_LOG_LEVEL_WARN:
+        return "warn";
+    }
+}
+
+bool report(sal_detail_LogLevel level, char const * area) {
+    assert(area != 0);
+    char const * env = std::getenv("SAL_LOG");
+    if (env == 0) {
+        env = "+WARN";
+    }
+    std::size_t areaLen = std::strlen(area);
+    enum Sense { POSITIVE = 0, NEGATIVE = 1 };
+    std::size_t senseLen[2] = { 0, 1 };
+        // initial senseLen[POSITIVE] < senseLen[NEGATIVE], so that if there are
+        // no matching switches at all, the result will be negative (and
+        // initializing with 1 is safe as the length of a valid switch, even
+        // without the "+"/"-" prefix, will always be > 1)
+    for (char const * p = env;;) {
+        Sense sense;
+        switch (*p++) {
+        case '\0':
+            return senseLen[POSITIVE] >= senseLen[NEGATIVE];
+                // if a specific item is both postiive and negative
+                // (senseLen[POSITIVE] == senseLen[NEGATIVE]), default to
+                // positive
+        case '+':
+            sense = POSITIVE;
+            break;
+        case '-':
+            sense = NEGATIVE;
+            break;
+        default:
+            return true; // upon an illegal SAL_LOG value, enable everything
+        }
+        char const * p1 = p;
+        while (*p1 != '.' && *p1 != '+' && *p1 != '-' && *p1 != '\0') {
+            ++p1;
+        }
+        bool match;
+        if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("INFO"))) {
+            match = level == SAL_DETAIL_LOG_LEVEL_INFO;
+        } else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("WARN")))
+        {
+            match = level == SAL_DETAIL_LOG_LEVEL_WARN;
+        } else {
+            return true;
+                // upon an illegal SAL_LOG value, everything is considered
+                // positive
+        }
+        char const * p2 = p1;
+        while (*p2 != '+' && *p2 != '-' && *p2 != '\0') {
+            ++p2;
+        }
+        if (match) {
+            if (*p1 == '.') {
+                ++p1;
+                std::size_t n = p2 - p1;
+                if ((n == areaLen && equalStrings(p1, n, area, areaLen))
+                    || (n < areaLen && area[n] == '.'
+                        && equalStrings(p1, n, area, n)))
+                {
+                    senseLen[sense] = p2 - p;
+                }
+            } else {
+                senseLen[sense] = p1 - p;
+            }
+        }
+        p = p2;
+    }
+}
+
+void log(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    char const * message)
+{
+    std::ostringstream s;
+    s << toString(level) << ':' << area << ':' << OSL_DETAIL_GETPID << ':'
+        << osl::Thread::getCurrentIdentifier() << ':' << where << message
+        << '\n';
+    std::fputs(s.str().c_str(), stderr);
+}
+
+}
+
+void sal_detail_log(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    char const * message)
+{
+    if (report(level, area)) {
+        log(level, area, where, message);
+    }
+}
+
+void sal_detail_logFormat(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    char const * format, ...)
+{
+    if (report(level, area)) {
+        std::va_list args;
+        va_start(args, format);
+        osl::detail::logFormat(level, area, where, format, args);
+        va_end(args);
+    }
+}
+
+void osl::detail::logFormat(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    char const * format, std::va_list arguments)
+{
+    char buf[1024];
+    int const len = sizeof buf - RTL_CONSTASCII_LENGTH("...");
+    int n = vsnprintf(buf, len, format, arguments);
+    if (n < 0) {
+        std::strcpy(buf, "???");
+    } else if (n >= len) {
+        std::strcpy(buf + len - 1, "...");
+    }
+    log(level, area, where, buf);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/all/logformat.hxx b/sal/osl/all/logformat.hxx
new file mode 100644
index 0000000..f4589a7
--- /dev/null
+++ b/sal/osl/all/logformat.hxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * [ Copyright (C) 2011 Stephan Bergmann, Red Hat <sbergman at redhat.com> (initial
+ *   developer) ]
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef INCLUDED_SAL_OSL_ALL_LOGFORMAT_HXX
+#define INCLUDED_SAL_OSL_ALL_LOGFORMAT_HXX
+
+#include "sal/config.h"
+
+#include <cstdarg>
+
+#include "sal/log.h"
+
+namespace osl { namespace detail {
+
+void logFormat(
+    sal_detail_LogLevel level, char const * area, char const * where,
+    char const * format, std::va_list arguments);
+
+} }
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/all/makefile.mk b/sal/osl/all/makefile.mk
index d9db5b7..e76388a 100644
--- a/sal/osl/all/makefile.mk
+++ b/sal/osl/all/makefile.mk
@@ -50,18 +50,18 @@ CXXFLAGS+= $(LFS_CFLAGS)
 SLOFILES=	\
             $(SLO)$/utility.obj\
             $(SLO)$/filepath.obj\
-            $(SLO)$/formatstring.obj\
             $(SLO)$/debugbase.obj\
             $(SLO)$/loadmodulerelative.obj \
-            $(SLO)/printtrace.obj
+            $(SLO)/log.obj\
+            $(SLO)/trace.obj
 
 OBJFILES=	\
             $(OBJ)$/utility.obj\
             $(OBJ)$/filepath.obj\
-            $(OBJ)$/formatstring.obj\
             $(OBJ)$/debugbase.obj\
             $(OBJ)$/loadmodulerelative.obj \
-            $(OBJ)/printtrace.obj
+            $(OBJ)/log.obj\
+            $(OBJ)/trace.obj
 
 # --- Targets ------------------------------------------------------
 
diff --git a/sal/osl/all/printtrace.cxx b/sal/osl/all/printtrace.cxx
deleted file mode 100644
index 0ecd6f4..0000000
--- a/sal/osl/all/printtrace.cxx
+++ /dev/null
@@ -1,68 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
-*
-* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-*
-* Copyright 2000, 2010 Oracle and/or its affiliates.
-*
-* OpenOffice.org - a multi-platform office productivity suite
-*
-* This file is part of OpenOffice.org.
-*
-* OpenOffice.org is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Lesser General Public License version 3
-* only, as published by the Free Software Foundation.
-*
-* OpenOffice.org is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU Lesser General Public License version 3 for more details
-* (a copy is included in the LICENSE file that accompanied this code).
-*
-* You should have received a copy of the GNU Lesser General Public License
-* version 3 along with OpenOffice.org.  If not, see
-* <http://www.openoffice.org/license.html>
-* for a copy of the LGPLv3 License.
-*
-************************************************************************/
-
-#include "precompiled_sal.hxx"
-
-#include "sal/config.h"
-
-#include <cstdarg>
-#include <cstdio>
-#include <cstring>
-
-#include <stdio.h> // snprintf, vsnprintf
-
-#include "osl/diagnose.h"
-#include "osl/thread.hxx"
-#include "rtl/string.h"
-#include "sal/types.h"
-
-#include "printtrace.h"
-
-void printTrace(unsigned long pid, char const * format, std::va_list arguments)
-{
-    char buf[1024];
-    int n1 = snprintf(
-        buf, sizeof buf, "Trace %lu/%" SAL_PRIuUINT32 ": \"", pid,
-        osl::Thread::getCurrentIdentifier());
-    OSL_ASSERT(
-        n1 >= 0 &&
-        (static_cast< unsigned int >(n1) <
-         sizeof buf - RTL_CONSTASCII_LENGTH("\"...\n")));
-    int n2 = sizeof buf - n1 - RTL_CONSTASCII_LENGTH("\"...\n");
-    int n3 = vsnprintf(buf + n1, n2, format, arguments);
-    if (n3 < 0) {
-        std::strcpy(buf + n1, "\"???\n");
-    } else if (n3 < n2) {
-        std::strcpy(buf + n1 + n3, "\"\n");
-    } else {
-        std::strcpy(buf + n1 + n2 - 1, "\"...\n");
-    }
-    std::fputs(buf, stderr);
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/all/trace.cxx b/sal/osl/all/trace.cxx
new file mode 100644
index 0000000..8357047
--- /dev/null
+++ b/sal/osl/all/trace.cxx
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * [ Copyright (C) 2011 Stephan Bergmann, Red Hat <sbergman at redhat.com> (initial
+ *   developer) ]
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "precompiled_sal.hxx"
+#include "sal/config.h"
+
+#include <cstdarg>
+
+#include "osl/diagnose.h"
+#include "sal/log.h"
+
+#include "logformat.hxx"
+
+void osl_trace(char const * pszFormat, ...) {
+    std::va_list args;
+    va_start(args, pszFormat);
+    osl::detail::logFormat(
+        SAL_DETAIL_LOG_LEVEL_INFO, "legacy.osl", SAL_WHERE, pszFormat, args);
+    va_end(args);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/inc/printtrace.h b/sal/osl/inc/printtrace.h
deleted file mode 100644
index a2bca91..0000000
--- a/sal/osl/inc/printtrace.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
-*
-* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-*
-* Copyright 2000, 2010 Oracle and/or its affiliates.
-*
-* OpenOffice.org - a multi-platform office productivity suite
-*
-* This file is part of OpenOffice.org.
-*
-* OpenOffice.org is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Lesser General Public License version 3
-* only, as published by the Free Software Foundation.
-*
-* OpenOffice.org is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU Lesser General Public License version 3 for more details
-* (a copy is included in the LICENSE file that accompanied this code).
-*
-* You should have received a copy of the GNU Lesser General Public License
-* version 3 along with OpenOffice.org.  If not, see
-* <http://www.openoffice.org/license.html>
-* for a copy of the LGPLv3 License.
-*
-************************************************************************/
-
-#ifndef INCLUDED_SAL_OSL_INC_PRINTTRACE_H
-#define INCLUDED_SAL_OSL_INC_PRINTTRACE_H
-
-#include "sal/config.h"
-
-#include <stdarg.h>
-
-#if defined __cplusplus
-extern "C" {
-#endif
-
-/* called internally by osl_trace */
-void printTrace(unsigned long pid, char const * format, va_list arguments);
-
-#if defined __cplusplus
-}
-#endif
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/unx/conditn.c b/sal/osl/unx/conditn.c
index ac6c926..d7ab713 100644
--- a/sal/osl/unx/conditn.c
+++ b/sal/osl/unx/conditn.c
@@ -26,12 +26,15 @@
  *
  ************************************************************************/
 
+#include "sal/config.h"
+
+#include <assert.h>
 
 #include "system.h"
+#include <sal/log.h>
 #include <sal/types.h>
 
 #include <osl/conditn.h>
-#include <osl/diagnose.h>
 #include <osl/time.h>
 
 
@@ -53,10 +56,9 @@ oslCondition SAL_CALL osl_createCondition()
 
     pCond = (oslConditionImpl*) malloc(sizeof(oslConditionImpl));
 
-    OSL_ASSERT(pCond);
-
     if ( pCond == 0 )
     {
+        SAL_WARN("sal", "std::bad_alloc in C");
         return 0;
     }
 
@@ -66,8 +68,9 @@ oslCondition SAL_CALL osl_createCondition()
     nRet =  pthread_cond_init(&pCond->m_Condition, PTHREAD_CONDATTR_DEFAULT);
     if ( nRet != 0 )
     {
-        OSL_TRACE("osl_createCondition : condition init failed. Errno: %d; '%s'\n",
-                  nRet, strerror(nRet));
+        SAL_WARN(
+            "sal", "pthread_cond_init failed, errno %d, \"%s\"", nRet,
+            strerror(nRet));
 
         free(pCond);
         return 0;
@@ -76,15 +79,14 @@ oslCondition SAL_CALL osl_createCondition()
     nRet = pthread_mutex_init(&pCond->m_Lock, PTHREAD_MUTEXATTR_DEFAULT);
     if ( nRet != 0 )
     {
-        OSL_TRACE("osl_createCondition : mutex init failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
+        SAL_WARN(
+            "sal", "pthread_mutex_init failed, errno %d, \"%s\"", nRet,
+            strerror(nRet));
 
         nRet = pthread_cond_destroy(&pCond->m_Condition);
-        if ( nRet != 0 )
-        {
-            OSL_TRACE("osl_createCondition : destroy condition failed. Errno: %d; '%s'\n",
-                      nRet, strerror(nRet));
-        }
+        SAL_WARN_IF(
+            nRet != 0, "sal", "pthread_cond_destroy failed, errno %d, \"%s\"",
+            nRet, strerror(nRet));
 
         free(pCond);
         pCond = 0;
@@ -106,17 +108,13 @@ void SAL_CALL osl_destroyCondition(oslCondition Condition)
         pCond = (oslConditionImpl*)Condition;
 
         nRet = pthread_cond_destroy(&pCond->m_Condition);
-        if ( nRet != 0 )
-        {
-            OSL_TRACE("osl_destroyCondition : destroy condition failed. Errno: %d; '%s'\n",
-                      nRet, strerror(nRet));
-        }
+        SAL_WARN_IF(
+            nRet != 0, "sal", "pthread_cond_destroy failed, errno %d, \"%s\"",
+            nRet, strerror(nRet));
         nRet = pthread_mutex_destroy(&pCond->m_Lock);
-        if ( nRet != 0 )
-        {
-            OSL_TRACE("osl_destroyCondition : destroy mutex failed. Errno: %d; '%s'\n",
-                      nRet, strerror(nRet));
-        }
+        SAL_WARN_IF(
+            nRet != 0, "sal", "pthread_mutex_destroy failed, errno %d, \"%s\"",
+            nRet, strerror(nRet));
 
         free(Condition);
     }
@@ -132,7 +130,7 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition)
    oslConditionImpl* pCond;
    int nRet=0;
 
-   OSL_ASSERT(Condition);
+   assert(Condition);
    pCond = (oslConditionImpl*)Condition;
 
    if ( pCond == 0 )
@@ -143,8 +141,9 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition)
    nRet = pthread_mutex_lock(&pCond->m_Lock);
    if ( nRet != 0 )
    {
-       OSL_TRACE("osl_setCondition : mutex lock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
+       SAL_WARN(
+           "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet,
+           strerror(nRet));
        return sal_False;
    }
 
@@ -152,16 +151,18 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition)
    nRet = pthread_cond_broadcast(&pCond->m_Condition);
    if ( nRet != 0 )
    {
-       OSL_TRACE("osl_setCondition : condition broadcast failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
+       SAL_WARN(
+           "sal", "pthread_cond_broadcast failed, errno %d, \"%s\"", nRet,
+           strerror(nRet));
        return sal_False;
    }
 
    nRet = pthread_mutex_unlock(&pCond->m_Lock);
    if ( nRet != 0 )
    {
-       OSL_TRACE("osl_setCondition : mutex unlock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
+       SAL_WARN(
+           "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet,
+           strerror(nRet));
        return sal_False;
    }
 
@@ -177,7 +178,7 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition)
     oslConditionImpl* pCond;
     int nRet=0;
 
-    OSL_ASSERT(Condition);
+    assert(Condition);
 
     pCond = (oslConditionImpl*)Condition;
 
@@ -189,8 +190,9 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition)
     nRet = pthread_mutex_lock(&pCond->m_Lock);
     if ( nRet != 0 )
     {
-       OSL_TRACE("osl_resetCondition : mutex lock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
+        SAL_WARN(
+            "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet,
+            strerror(nRet));
         return sal_False;
     }
 
@@ -199,8 +201,9 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition)
     nRet = pthread_mutex_unlock(&pCond->m_Lock);
     if ( nRet != 0 )
     {
-       OSL_TRACE("osl_resetCondition : mutex unlock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
+       SAL_WARN(
+           "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet,
+           strerror(nRet));
         return sal_False;
     }
 
@@ -216,7 +219,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time
     int nRet=0;
     oslConditionResult Result = osl_cond_result_ok;
 
-    OSL_ASSERT(Condition);
+    assert(Condition);
     pCond = (oslConditionImpl*)Condition;
 
     if ( pCond == 0 )
@@ -227,8 +230,9 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time
     nRet = pthread_mutex_lock(&pCond->m_Lock);
     if ( nRet != 0 )
     {
-       OSL_TRACE("osl_waitCondition : mutex lock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
+        SAL_WARN(
+            "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet,
+            strerror(nRet));
         return osl_cond_result_error;
     }
 
@@ -255,11 +259,10 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time
                     {
                         Result = osl_cond_result_timeout;
                         nRet = pthread_mutex_unlock(&pCond->m_Lock);
-                        if (nRet != 0)
-                        {
-                            OSL_TRACE("osl_waitCondition : mutex unlock failed. Errno: %d; %s\n",
-                                      nRet, strerror(nRet));
-                        }
+                        SAL_WARN_IF(
+                            nRet != 0, "sal",
+                            "pthread_mutex_unlock failed, errno %d, \"%s\"",
+                            nRet, strerror(nRet));
 
                         return Result;
                     }
@@ -267,14 +270,12 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time
                     {
                         Result = osl_cond_result_error;
                         nRet = pthread_mutex_unlock(&pCond->m_Lock);
-                        if ( nRet != 0 )
-                        {
-                            OSL_TRACE("osl_waitCondition : mutex unlock failed. Errno: %d; %s\n",
-                                      nRet, strerror(nRet));
-                        }
+                        SAL_WARN_IF(
+                            nRet != 0, "sal",
+                            "pthread_mutex_unlock failed, errno %d, \"%s\"",
+                            nRet, strerror(nRet));
                         return Result;
                     }
-/*                    OSL_TRACE("EINTR\n");*/
                 }
             }
             while ( !pCond->m_State );
@@ -287,15 +288,15 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time
             nRet = pthread_cond_wait(&pCond->m_Condition, &pCond->m_Lock);
             if ( nRet != 0 )
             {
-                OSL_TRACE("osl_waitCondition : condition wait failed. Errno: %d; %s\n",
-                          nRet, strerror(nRet));
+                SAL_WARN(
+                    "sal", "pthread_cond_wait failed, errno %d, \"%s\"", nRet,
+                    strerror(nRet));
                 Result = osl_cond_result_error;
                 nRet = pthread_mutex_unlock(&pCond->m_Lock);
-                if ( nRet != 0 )
-                {
-                    OSL_TRACE("osl_waitCondition : mutex unlock failed. Errno: %d; %s\n",
-                              nRet, strerror(nRet));
-                }
+                SAL_WARN_IF(
+                    nRet != 0, "sal",
+                    "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet,
+                    strerror(nRet));
 
                 return Result;
             }
@@ -303,11 +304,9 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time
     }
 
     nRet = pthread_mutex_unlock(&pCond->m_Lock);
-    if ( nRet != 0 )
-    {
-        OSL_TRACE("osl_waitCondition : mutex unlock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
-    }
+    SAL_WARN_IF(
+        nRet != 0, "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet,
+        strerror(nRet));
 
     return Result;
 }
@@ -321,7 +320,7 @@ sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition)
     oslConditionImpl* pCond;
     int nRet=0;
 
-    OSL_ASSERT(Condition);
+    assert(Condition);
     pCond = (oslConditionImpl*)Condition;
 
     if ( pCond == 0 )
@@ -330,20 +329,16 @@ sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition)
     }
 
     nRet = pthread_mutex_lock(&pCond->m_Lock);
-    if ( nRet != 0 )
-    {
-        OSL_TRACE("osl_checkCondition : mutex unlock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
-    }
+    SAL_WARN_IF(
+        nRet != 0, "sal", "pthread_mutex_lock failed, errno %d, \"%s\"", nRet,
+        strerror(nRet));
 
     State = pCond->m_State;
 
     nRet = pthread_mutex_unlock(&pCond->m_Lock);
-    if ( nRet != 0 )
-    {
-        OSL_TRACE("osl_checkCondition : mutex unlock failed. Errno: %d; %s\n",
-                  nRet, strerror(nRet));
-    }
+    SAL_WARN_IF(
+        nRet != 0, "sal", "pthread_mutex_unlock failed, errno %d, \"%s\"", nRet,
+        strerror(nRet));
 
     return State;
 }
diff --git a/sal/osl/unx/diagnose.c b/sal/osl/unx/diagnose.c
index 7832b16..5b46a61 100644
--- a/sal/osl/unx/diagnose.c
+++ b/sal/osl/unx/diagnose.c
@@ -46,7 +46,6 @@
 #endif
 
 #endif  /* HAVE_DLFCN_H */
-#include "osl/thread.h"
 
 #ifndef INCLUDED_PTHREAD_H
 #include <pthread.h>
@@ -58,8 +57,6 @@
 #define INCLUDED_STDDEF_H
 #endif
 
-#include "printtrace.h"
-
 /************************************************************************/
 /* Internal data structures and functions */
 /************************************************************************/
@@ -309,14 +306,4 @@ pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc (
     return pOldFunc;
 }
 
-/************************************************************************/
-/* osl_trace */
-/************************************************************************/
-void osl_trace(char const * pszFormat, ...) {
-    va_list args;
-    va_start(args, pszFormat);
-    printTrace((unsigned long) getpid(), pszFormat, args);
-    va_end(args);
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/w32/diagnose.c b/sal/osl/w32/diagnose.c
index f8fc997..6e793c3 100644
--- a/sal/osl/w32/diagnose.c
+++ b/sal/osl/w32/diagnose.c
@@ -29,9 +29,6 @@
 #include "system.h"
 
 #include <osl/diagnose.h>
-#include <osl/thread.h>
-
-#include "printtrace.h"
 
 static pfunc_osl_printDebugMessage  _pPrintDebugMessage = NULL;
 static pfunc_osl_printDetailedDebugMessage  _pPrintDetailedDebugMessage = NULL;
@@ -63,24 +60,6 @@ void SAL_CALL osl_breakDebug(void)
         abort ();
 }
 
-void osl_trace(char const * pszFormat, ...) {
-    va_list args;
-    va_start(args, pszFormat);
-    if ( IsDebuggerPresent() )
-    {
-        sal_Char    szMessage[512];
-        int written = _vsnprintf(
-            szMessage, sizeof(szMessage) - 2, pszFormat, args );
-        if ( written == -1 )
-            written = sizeof(szMessage) - 2;
-        szMessage[ written++ ] = '\n';
-        szMessage[ written ] = 0;
-        OutputDebugString( szMessage );
-    }
-    printTrace((unsigned long) _getpid(), pszFormat, args);
-    va_end(args);
-}
-
 sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage)
 {
     char const * env = getenv( "SAL_DIAGNOSE_ABORT" );
diff --git a/sal/rtl/source/logfile.cxx b/sal/rtl/source/logfile.cxx
index f71d8f5..c5858c1 100644
--- a/sal/rtl/source/logfile.cxx
+++ b/sal/rtl/source/logfile.cxx
@@ -39,10 +39,12 @@
 #include <osl/time.h>
 #include <osl/mutex.hxx>
 #include <rtl/bootstrap.h>
+#include <rtl/oustringostreaminserter.hxx>
 #include <rtl/ustring.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <rtl/alloc.h>
 #include <rtl/instance.hxx>
+#include <sal/log.h>
 #include "osl/thread.h"
 
 #include <algorithm>
@@ -107,7 +109,8 @@ OUString getFileUrl( const OUString &name )
     if ( osl_getFileURLFromSystemPath( name.pData, &aRet.pData )
          != osl_File_E_None )
     {
-        OSL_ASSERT( false );
+        SAL_WARN_S(
+            "sal", "osl_getFileURLFromSystemPath failed for \"" << name << '"');
     }
 
     OUString aWorkingDirectory;

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list