1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: logger.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
36 #define CONFIG_LOGGER_SINGLETON "/singletons/com.sun.star.configuration.theLogger"
37 #define OUSTR( lit ) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( lit ) )
38 #define OU2A( ustr ) rtl::OUStringToOString( ustr, RTL_TEXTENCODING_UTF8 ).getStr()
39 #define A2OU( astr ) rtl::OUString::createFromAscii( astr )
41 static const sal_Char k_unspecifiedClass
[] = "configmgr";
42 static const sal_Char k_unspecifiedMethod
[] = "log-message";
47 //--------------------------------------------------------------------------
48 void Logger::log(sal_Int32 nLevel
, const char * msg
, const char * sourceMethod
, const char * sourceClass
) const
53 this->log(nLevel
,A2OU(msg
),sourceMethod
,sourceClass
);
56 //--------------------------------------------------------------------------
57 void Logger::log(sal_Int32 nLevel
, const rtl::OUString
& msg
, const char * sourceMethod
, const char * sourceClass
) const
59 if (!sourceClass
) sourceClass
= k_unspecifiedClass
;
60 if (!sourceMethod
) sourceMethod
= k_unspecifiedMethod
;
62 // this place can be used to further enrich or instrument log output
66 m_xLogger
->logp(nLevel
,A2OU(sourceClass
),A2OU(sourceMethod
),msg
);
68 catch (uno::Exception
& e
)
70 OSL_TRACE("Configuration Log failure: %s\n"
71 "Log message was [Level=%04d] %s::%s : %s\n",
72 OU2A(e
.Message
),int(nLevel
),sourceClass
,sourceMethod
,OU2A(msg
));
74 else if (nLevel
>= (LogLevel::SEVERE
- OSL_DEBUG_LEVEL
*(LogLevel::SEVERE
-LogLevel::WARNING
)))
75 OSL_TRACE("Configuration Log [%04d] %s::%s : %s\n", int(nLevel
),sourceClass
,sourceMethod
,OU2A(msg
));
79 //--------------------------------------------------------------------------
80 uno::Reference
< logging::XLogger
>
81 Logger::getUnoLoggerFromContext(uno::Reference
< uno::XComponentContext
> const & xContext
)
83 uno::Reference
< logging::XLogger
> xLogger
;
86 try { xContext
->getValueByName( OUSTR(CONFIG_LOGGER_SINGLETON
) ) >>= xLogger
; }
87 catch (uno::Exception
& ) {}
92 //--------------------------------------------------------------------------
94 } // namespace configmgr