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