| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 Google Inc. | |
| 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 // 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 OMAHA_TOOLS_SRC_GOOPDUMP_DUMP_LOG_H_ | |
| 17 #define OMAHA_TOOLS_SRC_GOOPDUMP_DUMP_LOG_H_ | |
| 18 | |
| 19 #include <windows.h> | |
| 20 #include <atlstr.h> | |
| 21 #include <vector> | |
| 22 #include "base/basictypes.h" | |
| 23 | |
| 24 // TODO(omaha): Can we use the other Omaha logging classes for this? | |
| 25 | |
| 26 namespace omaha { | |
| 27 | |
| 28 class DumpLogHandler { | |
| 29 public: | |
| 30 DumpLogHandler(); | |
| 31 virtual ~DumpLogHandler(); | |
| 32 | |
| 33 virtual void WriteLine(const TCHAR* line) = 0; | |
| 34 | |
| 35 private: | |
| 36 DISALLOW_EVIL_CONSTRUCTORS(DumpLogHandler); | |
| 37 }; | |
| 38 | |
| 39 class ConsoleDumpLogHandler : public DumpLogHandler { | |
| 40 public: | |
| 41 ConsoleDumpLogHandler(); | |
| 42 virtual ~ConsoleDumpLogHandler(); | |
| 43 | |
| 44 virtual void WriteLine(const TCHAR* line); | |
| 45 | |
| 46 private: | |
| 47 DISALLOW_EVIL_CONSTRUCTORS(ConsoleDumpLogHandler); | |
| 48 }; | |
| 49 | |
| 50 class DebugDumpLogHandler : public DumpLogHandler { | |
| 51 public: | |
| 52 DebugDumpLogHandler(); | |
| 53 virtual ~DebugDumpLogHandler(); | |
| 54 | |
| 55 virtual void WriteLine(const TCHAR* line); | |
| 56 | |
| 57 private: | |
| 58 DISALLOW_EVIL_CONSTRUCTORS(DebugDumpLogHandler); | |
| 59 }; | |
| 60 | |
| 61 class FileDumpLogHandler : public DumpLogHandler { | |
| 62 public: | |
| 63 FileDumpLogHandler(); | |
| 64 virtual ~FileDumpLogHandler(); | |
| 65 | |
| 66 void set_filename(const TCHAR* filename); | |
| 67 virtual void WriteLine(const TCHAR* line); | |
| 68 | |
| 69 private: | |
| 70 void WriteBufToFile(const void* buf, DWORD num_bytes_to_write); | |
| 71 | |
| 72 CString filename_; | |
| 73 DISALLOW_EVIL_CONSTRUCTORS(FileDumpLogHandler); | |
| 74 }; | |
| 75 | |
| 76 | |
| 77 class DumpLog { | |
| 78 public: | |
| 79 DumpLog(); | |
| 80 ~DumpLog(); | |
| 81 | |
| 82 // Enables output to the console. | |
| 83 void EnableConsole(bool enable); | |
| 84 | |
| 85 // Enables output to OutputDebugString(). | |
| 86 void EnableDebug(bool enable); | |
| 87 | |
| 88 // Adds a log handler to pipe content to. | |
| 89 // Not needed for console or debug, those are done separately. | |
| 90 // The class does not assume ownership of the pointer and the pointer must | |
| 91 // live until this class is destroyed. | |
| 92 void AddLogHandler(DumpLogHandler* log_handler); | |
| 93 | |
| 94 // Removes the log handler. Removal is done based on pointer equality. | |
| 95 void RemoveLogHandler(DumpLogHandler* log_handler); | |
| 96 | |
| 97 // Writes a line to each of the connected log handlers. | |
| 98 void WriteLine(const TCHAR* format, ...) const; | |
| 99 | |
| 100 private: | |
| 101 std::vector<DumpLogHandler*> log_handlers_; | |
| 102 | |
| 103 ConsoleDumpLogHandler console_handler_; | |
| 104 DebugDumpLogHandler debug_handler_; | |
| 105 | |
| 106 DISALLOW_EVIL_CONSTRUCTORS(DumpLog); | |
| 107 }; | |
| 108 | |
| 109 } // namespace omaha | |
| 110 | |
| 111 #endif // OMAHA_TOOLS_SRC_GOOPDUMP_DUMP_LOG_H_ | |
| 112 | |
| OLD | NEW |