1 /** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PANDA_TOOLING_INSPECTOR_WS_LOGGER_H 17 #define PANDA_TOOLING_INSPECTOR_WS_LOGGER_H 18 19 #include "utils/logger.h" 20 21 #include "websocketpp/logger/levels.hpp" 22 23 #include <string> 24 25 namespace panda::tooling::inspector { 26 class WsLogger { 27 using ChannelType = websocketpp::log::channel_type_hint::value; 28 using Level = websocketpp::log::level; 29 30 public: WsLogger(Level static_channels,ChannelType channel_type)31 WsLogger(Level static_channels, ChannelType channel_type) 32 : channel_type_(channel_type), static_channels_(static_channels) 33 { 34 } 35 36 void set_channels(Level channels); 37 static_test(Level channel)38 bool static_test(Level channel) const 39 { 40 return (channel & static_channels_) == channel; 41 } 42 dynamic_test(Level channel)43 bool dynamic_test(Level channel) const 44 { 45 return (channel & dynamic_channels_) == channel; 46 } 47 48 void write(Level channel, const std::string &string) const; 49 50 private: 51 Logger::Level channel_log_level(Level channel) const; 52 53 const ChannelType channel_type_; 54 const Level static_channels_; 55 Level dynamic_channels_ {0}; 56 }; 57 } // namespace panda::tooling::inspector 58 59 #endif // PANDA_TOOLING_INSPECTOR_WS_LOGGER_H 60