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.hxx,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 #ifndef CONFIGMGR_LOGGER_HXX
32 #define CONFIGMGR_LOGGER_HXX
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/util/logging/XLogger.hpp>
36 #include <com/sun/star/util/logging/LogLevel.hpp>
40 // -----------------------------------------------------------------------------
41 namespace uno
= com::sun::star::uno
;
42 namespace logging
= com::sun::star::util::logging
;
43 namespace LogLevel
= logging::LogLevel
;
45 /// class providing access to a log output sink in the context
48 uno::Reference
< logging::XLogger
> m_xLogger
;
50 Logger() : m_xLogger() {}
52 Logger(uno::Reference
< logging::XLogger
> const & xLogger
)
57 Logger(uno::Reference
< uno::XComponentContext
> const & xContext
)
58 : m_xLogger( getUnoLoggerFromContext(xContext
) )
61 sal_Int32
level() const
62 { return m_xLogger
.is() ? m_xLogger
->getLevel() : LogLevel::OFF
; }
64 bool isLogging(sal_Int32 nLogLevel
) const
65 { return m_xLogger
.is() && m_xLogger
->isLoggable(nLogLevel
); }
67 /// log output to the logger
68 void log(sal_Int32 nLevel
, const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const;
69 void log(sal_Int32 nLevel
, const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const;
71 void error(const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
72 { log( LogLevel::SEVERE
, msg
, sourceMethod
, sourceClass
); }
73 void error(const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
74 { log( LogLevel::SEVERE
, msg
, sourceMethod
, sourceClass
); }
76 void warning(const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
77 { log( LogLevel::WARNING
, msg
, sourceMethod
, sourceClass
); }
78 void warning(const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
79 { log( LogLevel::WARNING
, msg
, sourceMethod
, sourceClass
); }
81 void info(const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
82 { log( LogLevel::INFO
, msg
, sourceMethod
, sourceClass
); }
83 void info(const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
84 { log( LogLevel::INFO
, msg
, sourceMethod
, sourceClass
); }
86 void config(const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
87 { log( LogLevel::CONFIG
, msg
, sourceMethod
, sourceClass
); }
88 void config(const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
89 { log( LogLevel::CONFIG
, msg
, sourceMethod
, sourceClass
); }
91 void fine(const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
92 { log( LogLevel::FINE
, msg
, sourceMethod
, sourceClass
); }
93 void fine(const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
94 { log( LogLevel::FINE
, msg
, sourceMethod
, sourceClass
); }
96 void finer(const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
97 { log( LogLevel::FINER
, msg
, sourceMethod
, sourceClass
); }
98 void finer(const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
99 { log( LogLevel::FINER
, msg
, sourceMethod
, sourceClass
); }
101 void finest(const rtl::OUString
& msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
102 { log( LogLevel::FINEST
, msg
, sourceMethod
, sourceClass
); }
103 void finest(const char * msg
, const char * sourceMethod
= 0, const char * sourceClass
= 0) const
104 { log( LogLevel::FINEST
, msg
, sourceMethod
, sourceClass
); }
106 uno::Reference
< logging::XLogger
> getUnoLogger() const { return m_xLogger
; }
109 uno::Reference
< logging::XLogger
>
110 getUnoLoggerFromContext(uno::Reference
< uno::XComponentContext
> const & xContext
);
112 // -----------------------------------------------------------------------------
113 } // namespace configmgr
115 #endif // CONFIGMGR_LOGGER_HXX