My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License or as specified alternatively below. You may obtain a copy of
8  * the License at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * Major Contributor(s):
16  * Copyright (C) 2011 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
17  * (initial developer)
18  *
19  * All Rights Reserved.
20  *
21  * For minor contributions see the git repository.
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27  * instead of those above.
28  */
29 
30 #ifndef INCLUDED_SAL_DETAIL_LOG_H
31 #define INCLUDED_SAL_DETAIL_LOG_H
32 
33 #include "sal/config.h"
34 
35 #include "sal/types.h"
36 
39 /* This header makes available replacements working in both C and C++ for the
40  obsolete osl/diagnose.h functionality that in turn is used from both C and
41  C++ code and the obsolete tools/debug.hxx and
42  canvas/inc/canvas/verbosetrace.hxx functionality that uses printf-style
43  formatting. Once that obsolete functionality is removed, this header can be
44  removed, too.
45 
46  This header uses variadic macros in both C (where they are officially only
47  supported since C99) and C++ (where they are officially only supported since
48  C++11). It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
49  Express) already support them in their C and C++ dialects. See also
50  <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>.
51 
52  Avoid the use of other sal code in this header as much as possible, so that
53  this code can be called from other sal code without causing endless
54  recursion.
55 */
56 
57 #if defined __cplusplus
58 extern "C" {
59 #endif
60 
61 /*
62  Clang warns about 'sal_True && sal_True' (those being integers and not booleans)
63  when it sees preprocessed source (-save-temps or using icecream)
64 */
65 #if defined __cplusplus
66 #define SAL_LOG_TRUE true
67 #define SAL_LOG_FALSE false
68 #else
69 #define SAL_LOG_TRUE sal_True
70 #define SAL_LOG_FALSE sal_False
71 #endif
72 
73 enum sal_detail_LogLevel {
74  SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
75  SAL_DETAIL_LOG_LEVEL_DEBUG = SAL_MAX_ENUM
76 };
77 
78 SAL_DLLPUBLIC void SAL_CALL sal_detail_logFormat(
79  enum sal_detail_LogLevel level, char const * area, char const * where,
80  char const * format, ...)
81 /* TODO: enabling this will produce a huge amount of -Werror=format errors: */
82 #if defined GCC && 0
83  __attribute__((format(printf, 4, 5)))
84 #endif
85  ;
86 
87 #if defined __cplusplus
88 }
89 #endif
90 
91 #define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \
92  do { \
93  if (condition) { \
94  sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \
95  } \
96  } while (SAL_LOG_FALSE)
97 
98 #if defined SAL_LOG_INFO
99 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_TRUE
100 #else
101 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_FALSE
102 #endif
103 #if defined SAL_LOG_WARN
104 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_TRUE
105 #else
106 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_FALSE
107 #endif
108 
109 #define SAL_DETAIL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": "
110 
111 #define SAL_DETAIL_INFO_IF_FORMAT(condition, area, ...) \
112  SAL_DETAIL_LOG_FORMAT( \
113  SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \
114  area, SAL_DETAIL_WHERE, __VA_ARGS__)
115 
116 #define SAL_DETAIL_WARN_IF_FORMAT(condition, area, ...) \
117  SAL_DETAIL_LOG_FORMAT( \
118  SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \
119  area, SAL_DETAIL_WHERE, __VA_ARGS__)
120 
123 #endif
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */