1 // 2 // Copyright 2022 The Abseil Authors. 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 // https://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 #include "absl/log/internal/test_actions.h" 17 18 #include <cassert> 19 #include <iostream> 20 #include <string> 21 #include <type_traits> 22 23 #include "absl/base/attributes.h" 24 #include "absl/base/config.h" 25 #include "absl/strings/escaping.h" 26 #include "absl/strings/str_cat.h" 27 #include "absl/strings/string_view.h" 28 #include "absl/time/time.h" 29 30 namespace absl { 31 ABSL_NAMESPACE_BEGIN 32 namespace log_internal { 33 operator ()(const absl::LogEntry & entry) const34void WriteToStderrWithFilename::operator()(const absl::LogEntry& entry) const { 35 std::cerr << message << " (file: " << entry.source_filename() << ")\n"; 36 } 37 operator ()(const absl::LogEntry & entry) const38void WriteEntryToStderr::operator()(const absl::LogEntry& entry) const { 39 if (!message.empty()) std::cerr << message << "\n"; 40 41 const std::string source_filename = absl::CHexEscape(entry.source_filename()); 42 const std::string source_basename = absl::CHexEscape(entry.source_basename()); 43 const std::string text_message = absl::CHexEscape(entry.text_message()); 44 const std::string encoded_message = absl::CHexEscape(entry.encoded_message()); 45 std::string encoded_message_str; 46 std::cerr << "LogEntry{\n" // 47 << " source_filename: \"" << source_filename << "\"\n" // 48 << " source_basename: \"" << source_basename << "\"\n" // 49 << " source_line: " << entry.source_line() << "\n" // 50 << " prefix: " << (entry.prefix() ? "true\n" : "false\n") // 51 << " log_severity: " << entry.log_severity() << "\n" // 52 << " timestamp: " << entry.timestamp() << "\n" // 53 << " text_message: \"" << text_message << "\"\n" // 54 << " verbosity: " << entry.verbosity() << "\n" // 55 << " encoded_message (raw): \"" << encoded_message << "\"\n" // 56 << encoded_message_str // 57 << "}\n"; 58 } 59 operator ()(absl::LogSeverity severity,absl::string_view filename,absl::string_view log_message) const60void WriteEntryToStderr::operator()(absl::LogSeverity severity, 61 absl::string_view filename, 62 absl::string_view log_message) const { 63 if (!message.empty()) std::cerr << message << "\n"; 64 const std::string source_filename = absl::CHexEscape(filename); 65 const std::string text_message = absl::CHexEscape(log_message); 66 std::cerr << "LogEntry{\n" // 67 << " source_filename: \"" << source_filename << "\"\n" // 68 << " log_severity: " << severity << "\n" // 69 << " text_message: \"" << text_message << "\"\n" // 70 << "}\n"; 71 } 72 73 } // namespace log_internal 74 ABSL_NAMESPACE_END 75 } // namespace absl 76