Chromium Code Reviews| Index: components/device_event_log/device_event_log.h |
| diff --git a/components/device_event_log/device_event_log.h b/components/device_event_log/device_event_log.h |
| index 7a0948606644cc7280d1f6bf50bdbfefc6cbbb4e..6643e43b08460055f5d6d53ebb774024bc2d4e26 100644 |
| --- a/components/device_event_log/device_event_log.h |
| +++ b/components/device_event_log/device_event_log.h |
| @@ -9,6 +9,7 @@ |
| #include <sstream> |
| #include "base/basictypes.h" |
| +#include "base/logging.h" |
| #include "base/timer/elapsed_timer.h" |
| #include "components/device_event_log/device_event_log_export.h" |
| @@ -34,12 +35,22 @@ |
| #define USB_LOG(level) \ |
| DEVICE_LOG(::device_event_log::LOG_TYPE_USB, \ |
| ::device_event_log::LOG_LEVEL_##level) |
| +#define HID_LOG(level) \ |
| + DEVICE_LOG(::device_event_log::LOG_TYPE_HID, \ |
| + ::device_event_log::LOG_LEVEL_##level) |
| +#define HID_PLOG(level) \ |
| + DEVICE_PLOG(::device_event_log::LOG_TYPE_HID, \ |
| + ::device_event_log::LOG_LEVEL_##level) |
| -// Generally prefer the above macros unless |type| or |level| is not constant. |
| +// Generally prefer the above macros unless |type| or |level| is not constant. |
| #define DEVICE_LOG(type, level) \ |
| ::device_event_log::internal::DeviceEventLogInstance(__FILE__, __LINE__, \ |
| type, level).stream() |
| +#define DEVICE_PLOG(type, level) \ |
| + ::device_event_log::internal::DeviceEventSystemErrorLogInstance( \ |
| + __FILE__, __LINE__, type, level, ::logging::GetLastSystemErrorCode()) \ |
| + .stream() |
| // Declare {Type_LOG_IF_SLOW() at the top of a method to log slow methods |
| // where "slow" is defined by kSlowMethodThresholdMs in the .cc file. |
| @@ -66,6 +77,8 @@ enum LogType { |
| LOG_TYPE_LOGIN, |
| // USB device related events (i.e. device/usb). |
| LOG_TYPE_USB, |
| + // Human-interface device related events (i.e. device/hid). |
| + LOG_TYPE_HID, |
| // Used internally |
| LOG_TYPE_UNKNOWN |
| }; |
| @@ -156,6 +169,29 @@ class DEVICE_EVENT_LOG_EXPORT DeviceEventLogInstance { |
| DISALLOW_COPY_AND_ASSIGN(DeviceEventLogInstance); |
| }; |
| +// Implementation class for DEVICE_PLOG macros. Provides a stream for creating |
| +// a log string and adds the event, including system error code, using |
| +// device_event_log::AddEntry on destruction. |
| +class DEVICE_EVENT_LOG_EXPORT DeviceEventSystemErrorLogInstance { |
| + public: |
| + DeviceEventSystemErrorLogInstance(const char* file, |
| + int line, |
| + device_event_log::LogType type, |
| + device_event_log::LogLevel level, |
| + logging::SystemErrorCode err); |
| + ~DeviceEventSystemErrorLogInstance(); |
| + |
| + std::ostream& stream() { return log_instance_.stream(); } |
| + |
| + private: |
| + // This system error will be appended to this embedded log instance's stream |
| + // at destruction. |
| + logging::SystemErrorCode err_; |
|
stevenjb
2015/02/23 22:46:46
nit: I was thinking of a comment above log_instanc
|
| + DeviceEventLogInstance log_instance_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DeviceEventSystemErrorLogInstance); |
| +}; |
| + |
| // Implementation class for SCOPED_LOG_IF_SLOW macros. Tests the elapsed time on |
| // destruction and adds a Debug or Error log entry if it exceeds the |
| // corresponding expected maximum elapsed time. |