source: rrlib_logging/test/test_messages.cpp @ 116:55042ce457ee

13.10
Last change on this file since 116:55042ce457ee was 116:55042ce457ee, checked in by Tobias Föhst <foehst@…>, 6 years ago

Bugfix for clang: removed ambiguous operator for function pointers

File size: 5.3 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    rrlib/logging/test/test_messages.cpp
23 *
24 * \author  Tobias Foehst
25 *
26 * \date    2010-06-16
27 *
28 */
29//----------------------------------------------------------------------
30
31//----------------------------------------------------------------------
32// External includes (system with <>, local with "")
33//----------------------------------------------------------------------
34#include <cstdlib>
35#include <iostream>
36#include <stdexcept>
37#include <iterator>
38#include <iomanip>
39
40extern "C"
41{
42#include <libgen.h>
43#include <unistd.h>
44}
45
46#include "rrlib/util/join.h"
47
48#include "rrlib/logging/configuration.h"
49#include "rrlib/logging/messages.h"
50
51//----------------------------------------------------------------------
52// Internal includes with ""
53//----------------------------------------------------------------------
54#include "rrlib/logging/test/libA/libA.h"
55#include "rrlib/logging/test/libB/libB.h"
56
57//----------------------------------------------------------------------
58// Debugging
59//----------------------------------------------------------------------
60
61//----------------------------------------------------------------------
62// Namespace usage
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Forward declarations / typedefs / enums
67//----------------------------------------------------------------------
68
69//----------------------------------------------------------------------
70// Const values
71//----------------------------------------------------------------------
72
73//----------------------------------------------------------------------
74// Implementation
75//----------------------------------------------------------------------
76
77namespace local
78{
79
80struct Test
81{
82  static void function()
83  {
84    RRLIB_LOG_PRINT_TO(my_domain, DEBUG_WARNING, "this ", "is a ", "local class test");
85
86    RRLIB_LOG_PRINT(WARNING, "foo");
87    RRLIB_LOG_PRINT_TO(my_domain, ERROR, "foo2");
88    if (true)
89    {
90      RRLIB_LOG_PRINTF_TO(my_domain, DEBUG, "%s\n", "FOO");
91    }
92  }
93};
94
95}
96
97struct TestStatic
98{
99  const char *GetLogDescription()
100  {
101    return "TestStatic";
102  }
103
104  static void StaticMethod()
105  {
106    RRLIB_LOG_PRINT_STATIC(USER, "From static method");
107  }
108
109  void NonStaticMethod()
110  {
111    RRLIB_LOG_PRINT(USER, "From non-static method");
112  }
113};
114
115
116int main(int argc, char **argv)
117{
118  rrlib::logging::default_log_description = basename(argv[0]);
119  rrlib::logging::SetLogFilenamePrefix(basename(argv[0]));
120
121#ifdef _LIB_RRLIB_XML_PRESENT_
122  if (!rrlib::logging::ConfigureFromFile("logging_config.xml"))
123  {
124    RRLIB_LOG_PRINT(ERROR, "Loading configuration failed!");
125    return EXIT_FAILURE;
126  }
127
128  rrlib::logging::PrintDomainConfigurations();
129#endif
130
131//  rrlib::logging::SetDomainPrintsName(".", true);
132//  rrlib::logging::SetDomainPrintsTime(".", true);
133//  rrlib::logging::SetDomainPrintsLevel(".", true);
134//  rrlib::logging::SetDomainPrintsLocation(".", true);
135//  rrlib::logging::SetDomainMaxMessageLevel(".", DEBUG_VERBOSE_3);
136//  rrlib::logging::SetDomainSink(".", rrlib::logging::eLOG_SINK_FILE);
137
138  rrlib::logging::SetDomainMaxMessageLevel(".example", rrlib::logging::tLogLevel::DEBUG_VERBOSE_3);
139//  rrlib::logging::SetDomainSink(".example", rrlib::logging::eLOG_SINK_STDOUT, rrlib::logging::eLOG_SINK_COMBINED_FILE);
140
141  RRLIB_LOG_PRINT(WARNING, "foo");
142
143  libA::Test();
144  libB::Test();
145
146  local::Test::function();
147
148  std::runtime_error exception("runtime_error");
149  std::exception &e(exception);
150  RRLIB_LOG_PRINT(ERROR, e);
151
152  RRLIB_LOG_PRINT(WARNING, "0x", std::setw(20), std::setfill('0'), std::hex, 324);
153
154  RRLIB_LOG_PRINT(ERROR, "Das hier ist ein mehrzeiliger\nFehler.\n");
155  RRLIB_LOG_PRINT(USER, "Und das hier ein mehrzeiliger\nText fuer den lieben Benutzer.");
156
157  const char* texts[] = {"Dies", "ist", "ein", "kleiner", "Text."};
158  RRLIB_LOG_PRINT(DEBUG, rrlib::util::Join(texts, texts + 5, " "));
159
160  TestStatic test_static;
161  test_static.StaticMethod();
162  test_static.NonStaticMethod();
163
164  int *a = 0;
165  const int *b = 0;
166  RRLIB_LOG_PRINT(DEBUG, "Pointer: ", a);
167  RRLIB_LOG_PRINT(DEBUG, "Const-Pointer: ", b);
168  RRLIB_LOG_PRINT(DEBUG, "Bool: ", true, false);
169  RRLIB_LOG_PRINT(DEBUG, "Mal noch einzelne Zeichen: ", 'a', '\0', 'b');
170
171  RRLIB_LOG_PRINT_TO(.speech_log, DEBUG, "This is a speech-log message");
172
173  std::cout << "Waiting 10 seconds for optional speech synthesis" << std::endl;
174  sleep(10);
175
176  rrlib::logging::PrintDomainConfigurations();
177  return EXIT_SUCCESS;
178}
Note: See TracBrowser for help on using the repository browser.