| Index: chromeos/network/network_event_log.h
|
| diff --git a/chromeos/network/network_event_log.h b/chromeos/network/network_event_log.h
|
| index 293144c5931d3617af074b234ba8f4fb0cecffa3..301e8060c12d9716bf76b2322fe77383556b61df 100644
|
| --- a/chromeos/network/network_event_log.h
|
| +++ b/chromeos/network/network_event_log.h
|
| @@ -13,6 +13,10 @@
|
| #include "base/time.h"
|
| #include "chromeos/chromeos_export.h"
|
|
|
| +namespace base {
|
| +class Value;
|
| +}
|
| +
|
| namespace chromeos {
|
|
|
| // Namespace for functions for logging network events.
|
| @@ -24,9 +28,19 @@ enum StringOrder {
|
| NEWEST_FIRST
|
| };
|
|
|
| +// Used to set the detail level for logging.
|
| +enum LogLevel {
|
| + LOG_LEVEL_ERROR = 0,
|
| + LOG_LEVEL_EVENT = 1,
|
| + LOG_LEVEL_DEBUG = 2
|
| +};
|
| +
|
| // Maximum number of event log entries, exported for testing.
|
| CHROMEOS_EXPORT extern const size_t kMaxNetworkEventLogEntries;
|
|
|
| +// Default log level.
|
| +CHROMEOS_EXPORT extern const LogLevel kDefaultLogLevel;
|
| +
|
| // Initializes / shuts down network event logging. Calling Initialize more than
|
| // once will reset the log.
|
| CHROMEOS_EXPORT void Initialize();
|
| @@ -35,29 +49,55 @@ CHROMEOS_EXPORT void Shutdown();
|
| // Returns true if network event logging has been initialized.
|
| CHROMEOS_EXPORT bool IsInitialized();
|
|
|
| -// Adds an entry to the event log. A maximum number of events are recorded
|
| -// after which new events replace old ones. Does nothing unless Initialize()
|
| -// has been called.
|
| -CHROMEOS_EXPORT void AddEntry(const std::string& module,
|
| +namespace internal {
|
| +
|
| +// Adds an entry to the event log at level specified by |log_level|.
|
| +// A maximum number of events are recorded after which new events replace
|
| +// old ones. Does nothing unless Initialize() has been called.
|
| +// NOTE: Generally use NET_LOG instead.
|
| +CHROMEOS_EXPORT void AddEntry(const char* file,
|
| + int file_line,
|
| + LogLevel log_level,
|
| const std::string& event,
|
| const std::string& description);
|
|
|
| -// Outputs the log to a formatted string. |order| determines which order to
|
| -// output the events. If |max_events| > 0, limits how many events are output.
|
| -CHROMEOS_EXPORT std::string GetAsString(StringOrder order, size_t max_events);
|
| -
|
| -// Macros to make logging format more consistent.
|
| -#define NET_LOG(module, message) \
|
| - ::chromeos::network_event_log::AddEntry( \
|
| - module, \
|
| - std::string(__FILE__) + ":" + ::base::StringPrintf("%d",__LINE__) + \
|
| - " (" + std::string(__func__) + ")", \
|
| - message)
|
| -
|
| -#define NET_LOG_WARNING(module, message) \
|
| - NET_LOG(module, std::string("WARNING:") + message)
|
| -#define NET_LOG_ERROR(module, message) \
|
| - NET_LOG(module, std::string("ERROR:") + message)
|
| +} // namespace internal
|
| +
|
| +// Outputs the log to a formatted string.
|
| +// |order| determines which order to output the events.
|
| +// |format| is a string that determines which elements to show. Elements
|
| +// must be comma-separated, e.g. "time,desc".
|
| +// Note: order of the format strings does not affect the output.
|
| +// "time" - Include a timestamp.
|
| +// "file" - Include file and line number.
|
| +// "desc" - Include the description.
|
| +// "html" - Include html tags.
|
| +// Only events with |log_level| <= |max_level| are included in the output.
|
| +// If |max_events| > 0, limits how many events are output.
|
| +CHROMEOS_EXPORT std::string GetAsString(StringOrder order,
|
| + const std::string& format,
|
| + LogLevel max_level,
|
| + size_t max_events);
|
| +
|
| +// Helper function for displaying a value as a string.
|
| +CHROMEOS_EXPORT std::string ValueAsString(const base::Value& value);
|
| +
|
| +// Errors
|
| +#define NET_LOG_ERROR(event, desc) NET_LOG_LEVEL( \
|
| + ::chromeos::network_event_log::LOG_LEVEL_ERROR, event, desc)
|
| +
|
| +// Important events, e.g. connection request
|
| +#define NET_LOG_EVENT(event, desc) NET_LOG_LEVEL( \
|
| + ::chromeos::network_event_log::LOG_LEVEL_EVENT, event, desc)
|
| +
|
| +// Non-essential debugging events
|
| +#define NET_LOG_DEBUG(event, desc) NET_LOG_LEVEL( \
|
| + ::chromeos::network_event_log::LOG_LEVEL_DEBUG, event, desc)
|
| +
|
| +// Macro to include file and line number info in the event log.
|
| +#define NET_LOG_LEVEL(log_level, event, description) \
|
| + ::chromeos::network_event_log::internal::AddEntry( \
|
| + __FILE__, __LINE__, log_level, event, description)
|
|
|
| } // namespace network_event_log
|
|
|
|
|