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

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

Issue 773703002: Generalize network_event_log -> device_event_log (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + feedback Created 6 years 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
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/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "chromeos/chromeos_export.h" 14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/device_event_log.h"
15 16
16 namespace base { 17 namespace base {
17 class Value; 18 class Value;
18 } 19 }
19 20
20 namespace chromeos { 21 namespace chromeos {
21 22
22 // Namespace for functions for logging network events. 23 // Namespace for functions for logging network events.
23 namespace network_event_log { 24 namespace network_event_log {
24 25
25 // Used to determine which order to output event entries in GetAsString.
26 enum StringOrder {
27 OLDEST_FIRST,
28 NEWEST_FIRST
29 };
30
31 // Used to set the detail level for logging.
32 enum LogLevel {
33 LOG_LEVEL_ERROR = 0,
34 LOG_LEVEL_USER = 1,
35 LOG_LEVEL_EVENT = 2,
36 LOG_LEVEL_DEBUG = 3
37 };
38
39 // Default log level.
40 CHROMEOS_EXPORT extern const LogLevel kDefaultLogLevel;
41
42 // Initializes / shuts down network event logging. Calling Initialize more than
43 // once will reset the log.
44 CHROMEOS_EXPORT void Initialize();
45 CHROMEOS_EXPORT void Shutdown();
46
47 // Returns true if network event logging has been initialized.
48 CHROMEOS_EXPORT bool IsInitialized();
49
50 namespace internal { 26 namespace internal {
51 27
52 // Gets the maximum number of log entries.
53 CHROMEOS_EXPORT size_t GetMaxLogEntries();
54
55 // Sets the maximum number of entries to something other than the default. If
56 // |max_entries| is less than the current maximum number of entries, this will
57 // delete any existing entries in excess of |max_entries|.
58 CHROMEOS_EXPORT void SetMaxLogEntries(size_t max_entries);
59
60 // Adds an entry to the event log at level specified by |log_level|. 28 // Adds an entry to the event log at level specified by |log_level|.
61 // A maximum number of events are recorded after which new events replace 29 // A maximum number of events are recorded after which new events replace
62 // old ones. Error events are prioritized such that error events will only be 30 // old ones. Error events are prioritized such that error events will only be
63 // deleted if more than least half of the entries are errors (at which point 31 // deleted if more than least half of the entries are errors (at which point
64 // the oldest error entry will be replaced). Does nothing unless Initialize() 32 // the oldest error entry will be replaced). Does nothing unless Initialize()
65 // has been called. NOTE: Generally use NET_LOG instead. 33 // has been called. NOTE: Generally use NET_LOG instead.
66 CHROMEOS_EXPORT void AddEntry(const char* file, 34 CHROMEOS_EXPORT void AddEntry(const char* file,
67 int file_line, 35 int file_line,
68 LogLevel log_level, 36 device_event_log::LogLevel log_level,
69 const std::string& event, 37 const std::string& event,
70 const std::string& description); 38 const std::string& description);
71 39
72 } // namespace internal 40 } // namespace internal
73 41
74 // Outputs the log to a formatted string.
75 // |order| determines which order to output the events.
76 // |format| is a string that determines which elements to show. Elements
77 // must be comma-separated, e.g. "time,desc".
78 // Note: order of the format strings does not affect the output.
79 // "time" - Include a timestamp.
80 // "file" - Include file and line number.
81 // "desc" - Include the description.
82 // "html" - Include html tags.
83 // "json" - Return as JSON format
84 // Only events with |log_level| <= |max_level| are included in the output.
85 // If |max_events| > 0, limits how many events are output.
86 // If |json| is specified, returns a JSON list of dictionaries containing time,
87 // level, file, event, and description.
88 CHROMEOS_EXPORT std::string GetAsString(StringOrder order,
89 const std::string& format,
90 LogLevel max_level,
91 size_t max_events);
92
93 // Helper function for displaying a value as a string. 42 // Helper function for displaying a value as a string.
94 CHROMEOS_EXPORT std::string ValueAsString(const base::Value& value); 43 CHROMEOS_EXPORT std::string ValueAsString(const base::Value& value);
95 44
96 // Errors 45 // Errors
97 #define NET_LOG_ERROR(event, desc) NET_LOG_LEVEL( \ 46 #define NET_LOG_ERROR(event, desc) \
98 ::chromeos::network_event_log::LOG_LEVEL_ERROR, event, desc) 47 NET_LOG_LEVEL(::chromeos::device_event_log::LOG_LEVEL_ERROR, event, desc)
99 48
100 // Chrome initiated events, e.g. connection requests, scan requests, 49 // Chrome initiated events, e.g. connection requests, scan requests,
101 // configuration removal (either from the UI or from ONC policy application). 50 // configuration removal (either from the UI or from ONC policy application).
102 #define NET_LOG_USER(event, desc) NET_LOG_LEVEL( \ 51 #define NET_LOG_USER(event, desc) \
103 ::chromeos::network_event_log::LOG_LEVEL_USER, event, desc) 52 NET_LOG_LEVEL(::chromeos::device_event_log::LOG_LEVEL_USER, event, desc)
104 53
105 // Important events, e.g. state updates 54 // Important events, e.g. state updates
106 #define NET_LOG_EVENT(event, desc) NET_LOG_LEVEL( \ 55 #define NET_LOG_EVENT(event, desc) \
107 ::chromeos::network_event_log::LOG_LEVEL_EVENT, event, desc) 56 NET_LOG_LEVEL(::chromeos::device_event_log::LOG_LEVEL_EVENT, event, desc)
108 57
109 // Non-essential debugging events 58 // Non-essential debugging events
110 #define NET_LOG_DEBUG(event, desc) NET_LOG_LEVEL( \ 59 #define NET_LOG_DEBUG(event, desc) \
111 ::chromeos::network_event_log::LOG_LEVEL_DEBUG, event, desc) 60 NET_LOG_LEVEL(::chromeos::device_event_log::LOG_LEVEL_DEBUG, event, desc)
112 61
113 // Macro to include file and line number info in the event log. 62 // Macro to include file and line number info in the event log.
114 #define NET_LOG_LEVEL(log_level, event, description) \ 63 #define NET_LOG_LEVEL(log_level, event, description) \
115 ::chromeos::network_event_log::internal::AddEntry( \ 64 ::chromeos::device_event_log::AddEntryWithDescription( \
116 __FILE__, __LINE__, log_level, event, description) 65 __FILE__, __LINE__, ::chromeos::device_event_log::LOG_TYPE_NETWORK, \
66 log_level, event, description)
117 67
118 } // namespace network_event_log 68 } // namespace network_event_log
119 69
120 } // namespace chromeos 70 } // namespace chromeos
121 71
122 #endif // CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_ 72 #endif // CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_
OLDNEW
« no previous file with comments | « chromeos/network/managed_network_configuration_handler_impl.cc ('k') | chromeos/network/network_event_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698