UDK 3.2.7 C/C++ API Reference

sal/detail/log.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*
00003  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2011 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
00017  *  (initial developer)
00018  *
00019  * All Rights Reserved.
00020  *
00021  * For minor contributions see the git repository.
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
00025  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
00026  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
00027  * instead of those above.
00028  */
00029 
00030 #ifndef INCLUDED_SAL_DETAIL_LOG_H
00031 #define INCLUDED_SAL_DETAIL_LOG_H
00032 
00033 #include "sal/config.h"
00034 
00035 #include "sal/saldllapi.h"
00036 #include "sal/types.h"
00037 
00040 /* This header makes available replacements working in both C and C++ for the
00041    obsolete osl/diagnose.h functionality that in turn is used from both C and
00042    C++ code and the obsolete tools/debug.hxx and
00043    canvas/inc/canvas/verbosetrace.hxx functionality that uses printf-style
00044    formatting.  Once that obsolete functionality is removed, this header can be
00045    removed, too.
00046 
00047    This header uses variadic macros in both C (where they are officially only
00048    supported since C99) and C++ (where they are officially only supported since
00049    C++11).  It appears that all relevant compilers (esp. GCC 4.0 and MS VS 2008
00050    Express) already support them in their C and C++ dialects.  See also
00051    <http://wiki.apache.org/stdcxx/C++0xCompilerSupport>.
00052 
00053    Avoid the use of other sal code in this header as much as possible, so that
00054    this code can be called from other sal code without causing endless
00055    recursion.
00056 */
00057 
00058 #if defined __cplusplus
00059 extern "C" {
00060 #endif
00061 
00062 /*
00063  Clang warns about 'sal_True && sal_True' (those being integers and not booleans)
00064  when it sees preprocessed source (-save-temps or using icecream)
00065 */
00066 #if defined __cplusplus
00067 #define SAL_LOG_TRUE true
00068 #define SAL_LOG_FALSE false
00069 #else
00070 #define SAL_LOG_TRUE sal_True
00071 #define SAL_LOG_FALSE sal_False
00072 #endif
00073 
00074 enum sal_detail_LogLevel {
00075     SAL_DETAIL_LOG_LEVEL_INFO, SAL_DETAIL_LOG_LEVEL_WARN,
00076     SAL_DETAIL_LOG_LEVEL_DEBUG = SAL_MAX_ENUM
00077 };
00078 
00079 SAL_DLLPUBLIC void SAL_CALL sal_detail_logFormat(
00080     enum sal_detail_LogLevel level, char const * area, char const * where,
00081     char const * format, ...)
00082 /* TODO: enabling this will produce a huge amount of -Werror=format errors: */
00083 #if defined GCC && 0
00084     __attribute__((format(printf, 4, 5)))
00085 #endif
00086     ;
00087 
00088 #if defined __cplusplus
00089 }
00090 #endif
00091 
00092 #define SAL_DETAIL_LOG_FORMAT(condition, level, area, where, ...) \
00093     do { \
00094         if (condition) { \
00095             sal_detail_logFormat((level), (area), (where), __VA_ARGS__); \
00096         } \
00097     } while (SAL_LOG_FALSE)
00098 
00099 #if defined SAL_LOG_INFO
00100 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_TRUE
00101 #else
00102 #define SAL_DETAIL_ENABLE_LOG_INFO SAL_LOG_FALSE
00103 #endif
00104 #if defined SAL_LOG_WARN
00105 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_TRUE
00106 #else
00107 #define SAL_DETAIL_ENABLE_LOG_WARN SAL_LOG_FALSE
00108 #endif
00109 
00110 #define SAL_DETAIL_WHERE __FILE__ ":" SAL_STRINGIFY(__LINE__) ": "
00111 
00112 #define SAL_DETAIL_INFO_IF_FORMAT(condition, area, ...) \
00113     SAL_DETAIL_LOG_FORMAT( \
00114         SAL_DETAIL_ENABLE_LOG_INFO && (condition), SAL_DETAIL_LOG_LEVEL_INFO, \
00115         area, SAL_DETAIL_WHERE, __VA_ARGS__)
00116 
00117 #define SAL_DETAIL_WARN_IF_FORMAT(condition, area, ...) \
00118     SAL_DETAIL_LOG_FORMAT( \
00119         SAL_DETAIL_ENABLE_LOG_WARN && (condition), SAL_DETAIL_LOG_LEVEL_WARN, \
00120         area, SAL_DETAIL_WHERE, __VA_ARGS__)
00121 
00124 #endif
00125 
00126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines