Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 5 | #ifndef DEBUGD_SRC_LOG_TOOL_H_ |
| 6 | #define DEBUGD_SRC_LOG_TOOL_H_ |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 7 | |
Gaurav Shah | f6c8f2a | 2012-10-11 17:22:43 -0700 | [diff] [blame] | 8 | #include <map> |
Ben Chan | 5facf4a | 2014-07-23 16:36:54 -0700 | [diff] [blame] | 9 | #include <string> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 10 | |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 11 | #include <base/files/scoped_file.h> |
Ben Chan | 657bed8 | 2014-09-02 20:40:51 -0700 | [diff] [blame] | 12 | #include <base/macros.h> |
Eric Caruso | cc7106c | 2017-04-27 14:22:42 -0700 | [diff] [blame] | 13 | #include <base/memory/ref_counted.h> |
| 14 | #include <dbus/bus.h> |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 15 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 16 | #include "debugd/src/anonymizer_tool.h" |
| 17 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 18 | namespace debugd { |
| 19 | |
| 20 | class LogTool { |
| 21 | public: |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame^] | 22 | // The encoding for a particular log. |
| 23 | enum class Encoding { |
| 24 | // Tries to see if the log output is valid UTF-8. Outputs it as-is if it is, |
| 25 | // or base64-encodes it otherwise. |
| 26 | kAutodetect, |
| 27 | |
| 28 | // Replaces any characters that are not valid UTF-8 encoded with the |
| 29 | // replacement character. |
| 30 | kUtf8, |
| 31 | |
| 32 | // base64-encodes the output. |
| 33 | kBinary |
| 34 | }; |
| 35 | |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 36 | explicit LogTool(scoped_refptr<dbus::Bus> bus) : bus_(bus) {} |
Ben Chan | 78f8953 | 2014-08-29 09:35:09 -0700 | [diff] [blame] | 37 | ~LogTool() = default; |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 38 | |
Ben Chan | 81905fb | 2017-02-08 22:03:11 -0800 | [diff] [blame] | 39 | using LogMap = std::map<std::string, std::string>; |
Elly Jones | 533c7c4 | 2012-08-10 15:07:05 -0400 | [diff] [blame] | 40 | |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 41 | std::string GetLog(const std::string& name); |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 42 | LogMap GetAllLogs(); |
Brian Norris | ca4fc04 | 2018-04-03 00:24:26 -0700 | [diff] [blame] | 43 | LogMap GetAllDebugLogs(); |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 44 | LogMap GetFeedbackLogs(); |
Eric Caruso | 0b24188 | 2018-04-04 13:43:46 -0700 | [diff] [blame] | 45 | void GetBigFeedbackLogs(const base::ScopedFD& fd); |
Eric Caruso | c93a15c | 2017-04-24 16:15:12 -0700 | [diff] [blame] | 46 | LogMap GetUserLogFiles(); |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 47 | |
Luis Hector Chavez | fc2566f | 2018-09-13 15:00:36 -0700 | [diff] [blame^] | 48 | // Returns a representation of |value| that is valid UTF-8 encoded. The value |
| 49 | // of |source_encoding| determines whether it will use Unicode U+FFFD |
| 50 | // REPLACEMENT CHARACTER or base64-encode the whole string in case there are |
| 51 | // invalid characters. |
| 52 | static std::string EnsureUTF8String(const std::string& value, |
| 53 | Encoding source_encoding); |
| 54 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 55 | private: |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 56 | friend class LogToolTest; |
| 57 | |
| 58 | void AnonymizeLogMap(LogMap* log_map); |
Eric Caruso | f9091f8 | 2017-04-28 14:18:59 -0700 | [diff] [blame] | 59 | void CreateConnectivityReport(); |
| 60 | |
| 61 | scoped_refptr<dbus::Bus> bus_; |
Darin Petkov | ce9b3a1 | 2013-01-10 16:38:54 +0100 | [diff] [blame] | 62 | |
Ahmed Fakhry | 21140cf | 2016-03-04 17:15:19 -0800 | [diff] [blame] | 63 | AnonymizerTool anonymizer_; |
| 64 | |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(LogTool); |
| 66 | }; |
| 67 | |
Ben Chan | a0011d8 | 2014-05-13 00:19:29 -0700 | [diff] [blame] | 68 | } // namespace debugd |
Elly Jones | 03cd6d7 | 2012-06-11 13:04:28 -0400 | [diff] [blame] | 69 | |
Alex Vakulenko | 262be3f | 2014-07-30 15:25:50 -0700 | [diff] [blame] | 70 | #endif // DEBUGD_SRC_LOG_TOOL_H_ |