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/saldllapi.h"
36 #include "sal/types.h"
37 
40 /* This header makes available replacements working in both C and C++ for the
41  obsolete osl/diagnose.h functionality that in turn is used from both C and
42  C++ code and the obsolete tools/debug.hxx and
43  canvas/inc/canvas/verbosetrace.hxx functionality that uses printf-style
44  formatting. Once that obsolete functionality is removed, this header can be
45  removed, too.
46 
47  This header uses variadic macros in both C (where they are officially only
48  supported since C99) and C++ (where they are officially only supported since
49  C++11). It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
50  Express) already support them in their C and C++ dialects. See also
51  <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>.
52 
53  Avoid the use of other sal code in this header as much as possible, so that
54  this code can be called from other sal code without causing endless
55  recursion.
56 */
57 
58 #if defined __cplusplus
59 extern "C" {
60 #endif
61 
62 /*
63  Clang warns about 'sal_True && sal_True' (those being integers and not booleans)
64  when it sees preprocessed source (-save-temps or using icecream)
65 */
66 #if defined __cplusplus
67 #define SAL_LOG_TRUE true
68 #define SAL_LOG_FALSE false
69 #else
70 #define SAL_LOG_TRUE sal_True
71 #define SAL_LOG_FALSE sal_False
72 #endif
73 
74 enum sal_detail_LogLevel {
75  SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
76  SAL_DETAIL_LOG_LEVEL_DEBUG = SAL_MAX_ENUM
77 };
78 
79 SAL_DLLPUBLIC void SAL_CALL sal_detail_logFormat(
80  enum sal_detail_LogLevel level, char const * area, char const * where,
81  char const * format, ...)
82 /* TODO: enabling this will produce a huge amount of -Werror=format errors: */
83 #if defined GCC && 0
84  __attribute__((format(printf, 4, 5)))
85 #endif
86  ;
87 
88 #if defined __cplusplus
89 }
90 #endif
91 
92 #define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \
93  do { \
94  if (condition) { \
95  sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \
96  } \
97  } while (SAL_LOG_FALSE)
98 
99 #if defined SAL_LOG_INFO
100 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_TRUE
101 #else
102 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_FALSE
103 #endif
104 #if defined SAL_LOG_WARN
105 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_TRUE
106 #else
107 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_FALSE
108 #endif
109 
110 #define SAL_DETAIL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": "
111 
112 #define SAL_DETAIL_INFO_IF_FORMAT(condition, area, ...) \
113  SAL_DETAIL_LOG_FORMAT( \
114  SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \
115  area, SAL_DETAIL_WHERE, __VA_ARGS__)
116 
117 #define SAL_DETAIL_WARN_IF_FORMAT(condition, area, ...) \
118  SAL_DETAIL_LOG_FORMAT( \
119  SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \
120  area, SAL_DETAIL_WHERE, __VA_ARGS__)
121 
124 #endif
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */