LibreOffice
LibreOffice 6.0 SDK C/C++ API Reference
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 functionality that uses printf-style
23  formatting. Once that obsolete functionality is removed, this header can be
24  removed, too.
25 
26  This header uses variadic macros in both C (where they are officially only
27  supported since C99) and C++ (where they are officially only supported since
28  C++11). It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
29  Express) already support them in their C and C++ dialects. See also
30  <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>.
31 
32  Avoid the use of other sal code in this header as much as possible, so that
33  this code can be called from other sal code without causing endless
34  recursion.
35 */
36 
37 #if defined __cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  Clang warns about 'sal_True && sal_True' (those being integers and not booleans)
43  when it sees preprocessed source (-save-temps or using icecream)
44 */
45 #if defined __cplusplus
46 #define SAL_LOG_TRUE true
47 #define SAL_LOG_FALSE false
48 #else
49 #define SAL_LOG_TRUE sal_True
50 #define SAL_LOG_FALSE sal_False
51 #endif
52 
53 enum sal_detail_LogLevel {
54  SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
55  SAL_DETAIL_LOG_LEVEL_DEBUG = SAL_MAX_ENUM
56 };
57 
58 SAL_DLLPUBLIC void SAL_CALL sal_detail_logFormat(
59  enum sal_detail_LogLevel level, char const * area, char const * where,
60  char const * format, ...)
61 #if defined __GNUC__
62  __attribute__((format(printf, 4, 5)))
63 #endif
64  ;
65 
66 #if defined __cplusplus
67 }
68 #endif
69 
70 #define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \
71  do { \
72  if (condition) { \
73  sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \
74  } \
75  } while (SAL_LOG_FALSE)
76 
77 #if defined SAL_LOG_INFO
78 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_TRUE
79 #else
80 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_FALSE
81 #endif
82 #if defined SAL_LOG_WARN
83 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_TRUE
84 #else
85 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_FALSE
86 #endif
87 
88 #define SAL_DETAIL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": "
89 
90 #define SAL_DETAIL_INFO_IF_FORMAT(condition, area, ...) \
91  SAL_DETAIL_LOG_FORMAT( \
92  SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \
93  area, SAL_DETAIL_WHERE, __VA_ARGS__)
94 
95 #define SAL_DETAIL_WARN_IF_FORMAT(condition, area, ...) \
96  SAL_DETAIL_LOG_FORMAT( \
97  SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \
98  area, SAL_DETAIL_WHERE, __VA_ARGS__)
99 
102 #endif
103 
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_DLLPUBLIC
Definition: saldllapi.h:30
#define SAL_MAX_ENUM
Definition: types.h:228