xref: /aosp_15_r20/external/cronet/net/log/net_log_capture_mode.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_LOG_NET_LOG_CAPTURE_MODE_H_
6 #define NET_LOG_NET_LOG_CAPTURE_MODE_H_
7 
8 #include <stdint.h>
9 
10 #include "net/base/net_export.h"
11 
12 namespace net {
13 
14 // NetLogCaptureMode specifies the logging level.
15 //
16 // It is used to control which events are emitted to the log, and what level of
17 // detail is included in their parameters.
18 //
19 // The capture mode is expressed as a number, where higher values imply more
20 // information.
21 //
22 // Note the numeric values are used in a bitfield (NetLogCaptureModeSet) so must
23 // be sequential starting from 0, and not exceed 31.
24 enum class NetLogCaptureMode : uint32_t {
25   // Default logging level, which is expected to be light-weight and
26   // does best-effort stripping of privacy/security sensitive data.
27   //
28   //  * Includes most HTTP request/response headers, but strips cookies and
29   //    auth.
30   //  * Does not include the full bytes read/written to sockets.
31   kDefault = 0,
32 
33   // Logging level that includes everything from kDefault, plus sensitive data
34   // that it may have strippped.
35   //
36   //  * Includes cookies and authentication headers.
37   //  * Does not include the full bytes read/written to sockets.
38   kIncludeSensitive,
39 
40   // Logging level that includes everything that is possible to be logged.
41   //
42   //  * Includes the actual bytes read/written to sockets
43   //  * Will result in large log files.
44   kEverything,
45 
46   kLast = kEverything,
47 };
48 
49 // Bitfield of NetLogCaptureMode, that should be initialized to zero for empty
50 // set. Bit "i" being set means that the set contains NetLogCaptureMode with
51 // value "i".
52 //
53 // Use the NetLogCaptureModeSet*() functions to operate on it.
54 using NetLogCaptureModeSet = uint32_t;
55 
NetLogCaptureModeToBit(NetLogCaptureMode capture_mode)56 inline NetLogCaptureModeSet NetLogCaptureModeToBit(
57     NetLogCaptureMode capture_mode) {
58   return 1 << static_cast<uint32_t>(capture_mode);
59 }
60 
NetLogCaptureModeSetContains(NetLogCaptureMode capture_mode,NetLogCaptureModeSet set)61 inline bool NetLogCaptureModeSetContains(NetLogCaptureMode capture_mode,
62                                          NetLogCaptureModeSet set) {
63   return (set & NetLogCaptureModeToBit(capture_mode)) != 0;
64 }
65 
NetLogCaptureModeSetAdd(NetLogCaptureMode value,NetLogCaptureModeSet * set)66 inline bool NetLogCaptureModeSetAdd(NetLogCaptureMode value,
67                                     NetLogCaptureModeSet* set) {
68   return *set |= NetLogCaptureModeToBit(value);
69 }
70 
71 // Returns true if |capture_mode| permits logging sensitive values such as
72 // cookies and credentials.
73 NET_EXPORT bool NetLogCaptureIncludesSensitive(NetLogCaptureMode capture_mode);
74 
75 // Returns true if |capture_mode| permits logging the full request/response
76 // bytes from sockets.
77 NET_EXPORT bool NetLogCaptureIncludesSocketBytes(
78     NetLogCaptureMode capture_mode);
79 
80 }  // namespace net
81 
82 #endif  // NET_LOG_NET_LOG_CAPTURE_MODE_H_
83