1 // Copyright 2019 Google LLC 2 // 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 // https://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 #ifndef SANDBOXED_API_SANDBOX2_LOGSINK_H_ 16 #define SANDBOXED_API_SANDBOX2_LOGSINK_H_ 17 18 #include "absl/log/log_entry.h" 19 #include "absl/log/log_sink.h" 20 #include "absl/synchronization/mutex.h" 21 #include "sandboxed_api/sandbox2/comms.h" 22 23 namespace sandbox2 { 24 25 // The LogSink will register itself with the facilities and forward all log 26 // messages to the executor on a given file descriptor. 27 class LogSink : public absl::LogSink { 28 public: 29 static constexpr char kLogFDName[] = "sb2_logsink"; 30 31 explicit LogSink(int fd); 32 ~LogSink() override; 33 34 LogSink(const LogSink&) = delete; 35 LogSink& operator=(const LogSink&) = delete; 36 37 void Send(const absl::LogEntry& e) override; 38 39 private: 40 Comms comms_; 41 42 // Needed to make the LogSink thread safe. 43 absl::Mutex lock_; 44 }; 45 46 } // namespace sandbox2 47 48 #endif // SANDBOXED_API_SANDBOX2_LOGSINK_H_ 49