Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / network / network_event_log.h
blob293144c5931d3617af074b234ba8f4fb0cecffa3
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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_
6 #define CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_
8 #include <deque>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/stringprintf.h"
13 #include "base/time.h"
14 #include "chromeos/chromeos_export.h"
16 namespace chromeos {
18 // Namespace for functions for logging network events.
19 namespace network_event_log {
21 // Used to determine which order to output event entries in GetAsString.
22 enum StringOrder {
23 OLDEST_FIRST,
24 NEWEST_FIRST
27 // Maximum number of event log entries, exported for testing.
28 CHROMEOS_EXPORT extern const size_t kMaxNetworkEventLogEntries;
30 // Initializes / shuts down network event logging. Calling Initialize more than
31 // once will reset the log.
32 CHROMEOS_EXPORT void Initialize();
33 CHROMEOS_EXPORT void Shutdown();
35 // Returns true if network event logging has been initialized.
36 CHROMEOS_EXPORT bool IsInitialized();
38 // Adds an entry to the event log. A maximum number of events are recorded
39 // after which new events replace old ones. Does nothing unless Initialize()
40 // has been called.
41 CHROMEOS_EXPORT void AddEntry(const std::string& module,
42 const std::string& event,
43 const std::string& description);
45 // Outputs the log to a formatted string. |order| determines which order to
46 // output the events. If |max_events| > 0, limits how many events are output.
47 CHROMEOS_EXPORT std::string GetAsString(StringOrder order, size_t max_events);
49 // Macros to make logging format more consistent.
50 #define NET_LOG(module, message) \
51 ::chromeos::network_event_log::AddEntry( \
52 module, \
53 std::string(__FILE__) + ":" + ::base::StringPrintf("%d",__LINE__) + \
54 " (" + std::string(__func__) + ")", \
55 message)
57 #define NET_LOG_WARNING(module, message) \
58 NET_LOG(module, std::string("WARNING:") + message)
59 #define NET_LOG_ERROR(module, message) \
60 NET_LOG(module, std::string("ERROR:") + message)
62 } // namespace network_event_log
64 } // namespace chromeos
66 #endif // CHROMEOS_NETWORK_NETWORK_EVENT_LOG_H_