LibreOffice: sal/detail/log.h Source File

LibreOffice LibreOffice 4.4 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

log.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef INCLUDED_SAL_DETAIL_LOG_H
11 #define INCLUDED_SAL_DETAIL_LOG_H
12
13 #include <sal/config.h>
14
15 #include <sal/saldllapi.h>
16 #include <sal/types.h>
17
20 /* This header makes available replacements working in both C and C++ for the
21 obsolete osl/diagnose.h functionality that in turn is used from both C and
22 C++ code and the obsolete tools/debug.hxx and
23 canvas/inc/canvas/verbosetrace.hxx functionality that uses printf-style
24 formatting. Once that obsolete functionality is removed, this header can be
25 removed, too.
26
27 This header uses variadic macros in both C (where they are officially only
28 supported since C99) and C++ (where they are officially only supported since
29 C++11). It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
30 Express) already support them in their C and C++ dialects. See also
31 <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>.
32
33 Avoid the use of other sal code in this header as much as possible, so that
34 this code can be called from other sal code without causing endless
35 recursion.
36 */
37
38 #if defined __cplusplus
39 extern "C" {
40 #endif
41
42 /*
43 Clang warns about 'sal_True && sal_True' (those being integers and not booleans)
44 when it sees preprocessed source (-save-temps or using icecream)
45 */
46 #if defined __cplusplus
47 #define SAL_LOG_TRUE true
48 #define SAL_LOG_FALSE false
49 #else
50 #define SAL_LOG_TRUE sal_True
51 #define SAL_LOG_FALSE sal_False
52 #endif
53
54 enum sal_detail_LogLevel {
55 SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
56 SAL_DETAIL_LOG_LEVEL_DEBUG = SAL_MAX_ENUM
57 };
58
59 SAL_DLLPUBLIC void SAL_CALL sal_detail_logFormat(
60 enum sal_detail_LogLevel level, char const * area, char const * where,
61 char const * format, ...)
62 /* TODO: enabling this will produce a huge amount of -Werror=format errors: */
63 #if defined __GNUC__ && 0
64 __attribute__((format(printf, 4, 5)))
65 #endif
66 ;
67
68 #if defined __cplusplus
69 }
70 #endif
71
72 #define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \
73 do { \
74 if (condition) { \
75 sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \
76 } \
77 } while (SAL_LOG_FALSE)
78
79 #if defined SAL_LOG_INFO
80 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_TRUE
81 #else
82 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_FALSE
83 #endif
84 #if defined SAL_LOG_WARN
85 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_TRUE
86 #else
87 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_FALSE
88 #endif
89
90 #define SAL_DETAIL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": "
91
92 #define SAL_DETAIL_INFO_IF_FORMAT(condition, area, ...) \
93 SAL_DETAIL_LOG_FORMAT( \
94 SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \
95 area, SAL_DETAIL_WHERE, __VA_ARGS__)
96
97 #define SAL_DETAIL_WARN_IF_FORMAT(condition, area, ...) \
98 SAL_DETAIL_LOG_FORMAT( \
99 SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \
100 area, SAL_DETAIL_WHERE, __VA_ARGS__)
101
104 #endif
105
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
saldllapi.h
types.h
config.h
SAL_DLLPUBLIC
#define SAL_DLLPUBLIC
Definition: saldllapi.h:30