DART 6.13.2
Loading...
Searching...
No Matches
Logging-impl.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_COMMON_DETAIL_LOGGING_IMPL_HPP_
34#define DART_COMMON_DETAIL_LOGGING_IMPL_HPP_
35
37
38#if DART_HAVE_spdlog
39 #include <spdlog/spdlog.h>
40#else
41 #include <iostream>
42 #include <string>
43#endif
44
45namespace dart::common {
46
47#if !DART_HAVE_spdlog
48namespace detail {
49
50//==============================================================================
51template <typename S1, typename S2>
52void print(std::ostream& os, const S1& header, const S2& format_str, int color)
53{
54 os << "\033[1;" << color << "m" << header << "\033[0m " << format_str
55 << std::endl;
56}
57
58//==============================================================================
59template <typename S, typename Arg, typename... Args>
60void print(
61 std::ostream& os,
62 const S& header,
63 std::string format_str,
64 int color,
65 Arg&& arg,
66 Args&&... args)
67{
68 os << "\033[1;" << color << "m" << header << "\033[0m " << format_str
69 << " [args]: ";
70 os << std::forward<Arg>(arg);
71 ((os << ", " << std::forward<Args>(args)), ...);
72 os << std::endl;
73}
74
75} // namespace detail
76#endif
77
78//==============================================================================
79template <typename S, typename... Args>
80void trace(const S& format_str, [[maybe_unused]] Args&&... args)
81{
82#if DART_HAVE_spdlog
83 spdlog::trace(format_str, std::forward<Args>(args)...);
84#else
86 std::cout, "[trace]", format_str, 38, std::forward<Args>(args)...);
87#endif
88}
89
90//==============================================================================
91template <typename S, typename... Args>
92void debug(const S& format_str, [[maybe_unused]] Args&&... args)
93{
94#if DART_HAVE_spdlog
95 spdlog::debug(format_str, std::forward<Args>(args)...);
96#else
98 std::cout, "[debug]", format_str, 36, std::forward<Args>(args)...);
99#endif
100}
101
102//==============================================================================
103template <typename S, typename... Args>
104void info(const S& format_str, [[maybe_unused]] Args&&... args)
105{
106#if DART_HAVE_spdlog
107 spdlog::info(format_str, std::forward<Args>(args)...);
108#else
110 std::cout, "[info]", format_str, 32, std::forward<Args>(args)...);
111#endif
112}
113
114//==============================================================================
115template <typename S, typename... Args>
116void warn(const S& format_str, [[maybe_unused]] Args&&... args)
117{
118#if DART_HAVE_spdlog
119 spdlog::warn(format_str, std::forward<Args>(args)...);
120#else
122 std::cerr, "[warn]", format_str, 33, std::forward<Args>(args)...);
123#endif
124}
125
126//==============================================================================
127template <typename S, typename... Args>
128void error(const S& format_str, [[maybe_unused]] Args&&... args)
129{
130#if DART_HAVE_spdlog
131 spdlog::error(format_str, std::forward<Args>(args)...);
132#else
134 std::cerr, "[error]", format_str, 31, std::forward<Args>(args)...);
135#endif
136}
137
138//==============================================================================
139template <typename S, typename... Args>
140void fatal(const S& format_str, [[maybe_unused]] Args&&... args)
141{
142#if DART_HAVE_spdlog
143 spdlog::critical(format_str, std::forward<Args>(args)...);
144#else
146 std::cerr, "[fatal]", format_str, 35, std::forward<Args>(args)...);
147#endif
148}
149
150} // namespace dart::common
151
152#endif // DART_COMMON_DETAIL_LOGGING_IMPL_HPP_
void print(std::ostream &os, const S1 &header, const S2 &format_str, int color)
Definition Logging-impl.hpp:52
Definition Aspect.cpp:42
void fatal(const S &format_str, Args &&... args)
Logs for a fatal error message.
Definition Logging-impl.hpp:140
void info(const S &format_str, Args &&... args)
Logs for a information message.
Definition Logging-impl.hpp:104
void warn(const S &format_str, Args &&... args)
Logs for a warning message.
Definition Logging-impl.hpp:116
void trace(const S &format_str, Args &&... args)
Logs for a trace message.
Definition Logging-impl.hpp:80
void error(const S &format_str, Args &&... args)
Logs for a error message.
Definition Logging-impl.hpp:128
const bool debug
Definition urdf_world_parser.cpp:49