Apollo  6.0
Open source self driving car software
monitor_log_buffer.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
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 
22 #pragma once
23 
24 #include <memory>
25 #include <sstream>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 #include "gtest/gtest_prod.h"
32 #include "modules/common/monitor_log/proto/monitor_log.pb.h"
33 
38 namespace apollo {
39 namespace common {
40 namespace monitor {
41 
42 #define REG_MSG_TYPE(TYPE) \
43  MonitorLogBuffer &TYPE(const std::string &msg) { \
44  AddMonitorMsgItem(MonitorMessageItem::TYPE, msg); \
45  Publish(); \
46  return *this; \
47  } \
48  MonitorLogBuffer &TYPE() { \
49  level_ = MonitorMessageItem::TYPE; \
50  return *this; \
51  }
52 
61  public:
66  explicit MonitorLogBuffer(const MonitorMessageItem::MessageSource &source);
67 
68  virtual ~MonitorLogBuffer();
69 
73  REG_MSG_TYPE(INFO);
74 
78  REG_MSG_TYPE(WARN);
79 
83  REG_MSG_TYPE(ERROR);
84 
88  REG_MSG_TYPE(FATAL);
89 
95  void AddMonitorMsgItem(const MonitorMessageItem::LogLevel log_level,
96  const std::string &msg);
97 
101  void Publish();
102 
103  private:
105  MonitorMessageItem::LogLevel level_ = MonitorMessageItem::INFO;
106  std::vector<MessageItem> monitor_msg_items_;
107  MonitorMessageItem::MessageSource source_;
108 
109  FRIEND_TEST(MonitorBufferTest, RegisterMacro);
110  FRIEND_TEST(MonitorBufferTest, AddMonitorMsgItem);
111  FRIEND_TEST(MonitorBufferTest, Operator);
112 };
113 
114 } // namespace monitor
115 } // namespace common
116 } // namespace apollo
REG_MSG_TYPE(INFO)
record an INFO type message
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
This class helps collect and publish MonitorMessage pb to monitor topic. A module who wants to publis...
Definition: monitor_logger.h:51
MonitorLogBuffer(const MonitorMessageItem::MessageSource &source)
The constructor of MonitorBuffer.
void AddMonitorMsgItem(const MonitorMessageItem::LogLevel log_level, const std::string &msg)
Add monitor message with MonitorMessageItem::LogLevel.
The class of MonitorLogger.
void Publish()
publish the monitor messages
This class help collect MonitorMessage pb to monitor topic. The messages can be published automatical...
Definition: monitor_log_buffer.h:60