Gazebo Common

API Reference

6.0.1
Console.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef GZ_COMMON_CONSOLE_HH_
18#define GZ_COMMON_CONSOLE_HH_
19
20#include <spdlog/logger.h>
21#include <spdlog/spdlog.h>
22
23#include <fstream>
24#include <iostream>
25#include <ostream>
26#include <sstream>
27#include <string>
28
29#include <gz/common/Export.hh>
30#include <gz/common/Util.hh>
31#include <gz/utils/log/Logger.hh>
32#include <gz/utils/SuppressWarning.hh>
33
34namespace gz
35{
36 namespace common
37 {
39 class GZ_COMMON_VISIBLE LogMessage
40 {
45 public: LogMessage(const char *_file,
46 int _line,
47 spdlog::level::level_enum _logLevel);
48
50 public: ~LogMessage();
51
54 public: std::ostream &stream();
55
57 private: spdlog::level::level_enum severity;
58
60 private: spdlog::source_loc sourceLocation;
61
63 private: std::ostringstream ss;
64 };
65
67 #define gzcrit (gz::common::LogMessage( \
68 __FILE__, __LINE__, spdlog::level::critical).stream())
69
71 #define gzerr gz::common::LogMessage( \
72 __FILE__, __LINE__, spdlog::level::err).stream()
73
75 #define gzwarn gz::common::LogMessage( \
76 __FILE__, __LINE__, spdlog::level::warn).stream()
77
79 #define gzlog gz::common::LogMessage( \
80 __FILE__, __LINE__, spdlog::level::trace).stream()
81
83 #define gzmsg gz::common::LogMessage( \
84 __FILE__, __LINE__, spdlog::level::info).stream()
85
87 #define gzdbg gz::common::LogMessage( \
88 __FILE__, __LINE__, spdlog::level::debug).stream()
89
91 #define gztrace gz::common::LogMessage( \
92 __FILE__, __LINE__, spdlog::level::trace).stream()
93
101 #define gzLogInit(_dir, _file)\
102 gz::common::Console::Init(_dir, _file)
103
105 #define gzLogClose()\
106 gz::common::Console::Close()
107
110 #define gzLogDirectory()\
111 (gz::common::Console::Directory())
112
116 class GZ_COMMON_VISIBLE Console : public gz::utils::log::Logger
117 {
120 public: explicit Console(const std::string &_loggerName);
121
124 public: static Console &Root();
125
130 public: static bool Init(const std::string &_directory,
131 const std::string &_filename);
132
135 public: static void Close();
136
140 public: static std::string Directory();
141
150 public: static void SetVerbosity(const int _level);
151
155 public: static int Verbosity();
156
170 public: static void SetPrefix(const std::string &_customPrefix);
171
175 public: static std::string Prefix();
176
178 public: static bool initialized;
179
181 private: static int verbosity;
182
183 GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
185 private: static std::string customPrefix;
186
189 private: std::string logDirectory;
190 GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
191 };
192 }
193}
194#endif