Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: chromeos/network/network_event_log.h

Issue 14876021: Re-factor network_event_log (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_ 5 #ifndef CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_
6 #define CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_ 6 #define CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chromeos/chromeos_export.h" 14 #include "chromeos/chromeos_export.h"
15 15
16 namespace base {
17 class Value;
18 }
19
16 namespace chromeos { 20 namespace chromeos {
17 21
18 // Namespace for functions for logging network events. 22 // Namespace for functions for logging network events.
19 namespace network_event_log { 23 namespace network_event_log {
20 24
21 // Used to determine which order to output event entries in GetAsString. 25 // Used to determine which order to output event entries in GetAsString.
22 enum StringOrder { 26 enum StringOrder {
23 OLDEST_FIRST, 27 OLDEST_FIRST,
24 NEWEST_FIRST 28 NEWEST_FIRST
25 }; 29 };
26 30
31 // Used to set the detail level for logging.
32 enum LogLevel {
33 LOG_LEVEL_ERROR = 0,
34 LOG_LEVEL_EVENT = 1,
35 LOG_LEVEL_DEBUG = 2
36 };
37
27 // Maximum number of event log entries, exported for testing. 38 // Maximum number of event log entries, exported for testing.
28 CHROMEOS_EXPORT extern const size_t kMaxNetworkEventLogEntries; 39 CHROMEOS_EXPORT extern const size_t kMaxNetworkEventLogEntries;
29 40
41 // Default log level.
42 CHROMEOS_EXPORT extern const int kDefaultLogLevel;
43
30 // Initializes / shuts down network event logging. Calling Initialize more than 44 // Initializes / shuts down network event logging. Calling Initialize more than
31 // once will reset the log. 45 // once will reset the log.
32 CHROMEOS_EXPORT void Initialize(); 46 CHROMEOS_EXPORT void Initialize();
33 CHROMEOS_EXPORT void Shutdown(); 47 CHROMEOS_EXPORT void Shutdown();
34 48
35 // Returns true if network event logging has been initialized. 49 // Returns true if network event logging has been initialized.
36 CHROMEOS_EXPORT bool IsInitialized(); 50 CHROMEOS_EXPORT bool IsInitialized();
37 51
38 // Adds an entry to the event log. A maximum number of events are recorded 52 // Adds an entry to the event log at level specified by |log_level|.
39 // after which new events replace old ones. Does nothing unless Initialize() 53 // A maximum number of events are recorded after which new events replace
40 // has been called. 54 // old ones. Does nothing unless Initialize() has been called.
41 CHROMEOS_EXPORT void AddEntry(const std::string& module, 55 // NOTE: Generally use NET_LOG instead.
56 CHROMEOS_EXPORT void AddEntry(const char* file,
gauravsh 2013/05/13 00:34:51 When would one use this directly? If this is not m
stevenjb 2013/05/13 19:36:39 The unit tests call it directly. Moved to 'interna
57 int file_line,
58 LogLevel log_level,
42 const std::string& event, 59 const std::string& event,
43 const std::string& description); 60 const std::string& description);
44 61
45 // Outputs the log to a formatted string. |order| determines which order to 62 // Outputs the log to a formatted string.
46 // output the events. If |max_events| > 0, limits how many events are output. 63 // |order| determines which order to output the events.
47 CHROMEOS_EXPORT std::string GetAsString(StringOrder order, size_t max_events); 64 // |format| is a string that determines which elelements to show. Elements
65 // can be combined with or without separators, e.g. "time,desc".
pneubeck (no reviews) 2013/05/13 13:16:25 you're parsing the format string per entry. Since
stevenjb 2013/05/13 19:36:39 Made the optimization to only parse the string in
66 // Note: order of the format strings does not affect the output.
67 // "time" - Include a timestamp.
68 // "file" - Include file and line number.
69 // "desc" - Include the description.
70 // "html" - Include html tags.
71 // Only events with |log_level| >= |max_level| are included in the output.
gauravsh 2013/05/13 00:34:51 This should be |log_level| <= |max_level|.
stevenjb 2013/05/13 19:36:39 Done.
72 // If |max_events| > 0, limits how many events are output.
73 CHROMEOS_EXPORT std::string GetAsString(StringOrder order,
74 const std::string& format,
75 int max_level,
76 size_t max_events);
48 77
49 // Macros to make logging format more consistent. 78 // Utility function for displaying a DBus value as a string.
50 #define NET_LOG(module, message) \ 79 CHROMEOS_EXPORT std::string DBusValueAsString(const base::Value& value);
gauravsh 2013/05/13 00:34:51 NetworkEventLog is an odd place for this. I think
pneubeck (no reviews) 2013/05/13 13:16:25 There is already: operator<< in values.h and Jso
stevenjb 2013/05/13 19:36:39 Done.
51 ::chromeos::network_event_log::AddEntry( \
52 module, \
53 std::string(__FILE__) + ":" + ::base::StringPrintf("%d",__LINE__) + \
54 " (" + std::string(__func__) + ")", \
55 message)
56 80
57 #define NET_LOG_WARNING(module, message) \ 81 // Errors
58 NET_LOG(module, std::string("WARNING:") + message) 82 #define NET_LOG_ERROR(event, desc) NET_LOG_LEVEL( \
59 #define NET_LOG_ERROR(module, message) \ 83 ::chromeos::network_event_log::LOG_LEVEL_ERROR, event, desc)
60 NET_LOG(module, std::string("ERROR:") + message) 84
85 // Important events, e.g. connection request
86 #define NET_LOG_EVENT(event, desc) NET_LOG_LEVEL( \
87 ::chromeos::network_event_log::LOG_LEVEL_EVENT, event, desc)
88
89 // Non-essencial debugging events
gauravsh 2013/05/13 00:34:51 Non-essential
stevenjb 2013/05/13 19:36:39 Done.
90 #define NET_LOG_DEBUG(event, desc) NET_LOG_LEVEL( \
91 ::chromeos::network_event_log::LOG_LEVEL_DEBUG, event, desc)
92
93 // Macro to include file and line number info in the event log.
94 #define NET_LOG_LEVEL(log_level, event, description) \
95 ::chromeos::network_event_log::AddEntry( \
96 __FILE__, __LINE__, log_level, event, description)
pneubeck (no reviews) 2013/05/13 13:16:25 should be FROM_HERE
stevenjb 2013/05/13 19:36:39 FROM_HERE uses tracked_objects; I think that is mo
pneubeck (no reviews) 2013/05/16 08:21:07 What do you mean by "uses"? tracked_objects is the
61 97
62 } // namespace network_event_log 98 } // namespace network_event_log
63 99
64 } // namespace chromeos 100 } // namespace chromeos
65 101
66 #endif // CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_ 102 #endif // CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698