ecto
log.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 #pragma once
30 
31 #include <ecto/config.hpp>
32 
33 #if defined(ECTO_LOGGING)
34 #include <boost/format.hpp>
35 #endif
36 #include <ecto/util.hpp>
37 #include <ecto/test.hpp>
38 #include <stdint.h>
39 
40 namespace ecto {
41  ECTO_EXPORT void log(const char*, const char*, unsigned line, const std::string& msg);
42  ECTO_EXPORT void assert_failed(const char*, const char* file, unsigned line, const char* cond, const char* msg);
43  bool logging_on();
44 }
45 
46 #ifdef NDEBUG
47 #define ECTO_ASSERT(X, msg) do { ECTO_RANDOM_DELAY(); } while(false)
48 #else
49 #define ECTO_ASSERT(X, msg) \
50  do { \
51  ECTO_RANDOM_DELAY(); \
52  if (X) ; else ecto::assert_failed(__PRETTY_FUNCTION__, __FILE__, __LINE__, #X, msg); \
53  } while(false)
54 #endif
55 
56 #if defined(ECTO_LOGGING)
57 #define ECTO_LOG_DEBUG(fmt, args) \
58  do { \
59  ECTO_RANDOM_DELAY(); \
60  if (__builtin_expect((ecto::logging_on()), 0)) \
61  ::ecto::log(__PRETTY_FUNCTION__, __FILE__, __LINE__, str(boost::format(fmt) % args)); \
62  } while (false)
63 #define ECTO_START() ECTO_LOG_DEBUG(">>> %s", __PRETTY_FUNCTION__);
64 #define ECTO_FINISH() ECTO_LOG_DEBUG("<<< %s", __PRETTY_FUNCTION__);
65 #else
66 #define ECTO_LOG_DEBUG(fmg, args) do { ECTO_RANDOM_DELAY(); } while (false)
67 #define ECTO_START() do { ECTO_RANDOM_DELAY(); } while(false)
68 #define ECTO_FINISH() do { ECTO_RANDOM_DELAY(); } while(false)
69 #endif
70 
71 #ifdef ECTO_TRACE_EXCEPTIONS
72 #define ECTO_TRACE_EXCEPTION(E) ECTO_LOG_DEBUG("CAUGHT: %s", E);
73 #else
74 #define ECTO_TRACE_EXCEPTION(E)
75 #endif
76 
#define ECTO_EXPORT
Definition: util.hpp:49
ECTO_EXPORT void log(const char *, const char *, unsigned line, const std::string &msg)
Definition: parameters.hpp:11
ECTO_EXPORT void assert_failed(const char *, const char *file, unsigned line, const char *cond, const char *msg)
bool logging_on()