1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Logwise logging integration for exfiltrate.
//!
//! This module provides integration with the logwise logging framework, allowing
//! log records to be captured and forwarded through the exfiltrate system via
//! JSON-RPC notifications. This is particularly useful for capturing and analyzing
//! logs from remote or embedded systems.
//!
//! # Overview
//!
//! The module implements a custom `Logger` that intercepts logwise log records
//! and forwards them as JSON-RPC notifications through the internal proxy system.
//! This allows logs to be collected, analyzed, and stored by external systems
//! that connect to the exfiltrate proxy.
//!
//! # Architecture
//!
//! The logging capture works by:
//! 1. Installing a custom `ForwardingLogger` as a global logger in logwise
//! 2. Intercepting all log records that flow through logwise
//! 3. Converting log records to JSON-RPC notifications
//! 4. Forwarding notifications through the internal proxy for external consumption
//!
//! # Examples
//!
//! ## Basic usage
//!
//! ```
//! # // This example won't actually run the capture since it requires a proxy connection
//! # fn main() {
//! // Note: begin_capture() requires the logwise feature to be enabled
//! # #[cfg(feature = "logwise")]
//! # {
//! // Start capturing logwise logs
//! // exfiltrate::logwise::begin_capture();
//!
//! // Example of what would be captured (using logwise directly)
//! // logwise::info_sync!("This log would be captured", user="alice");
//! # }
//! # }
//! ```
//!
//! ## With complex types
//!
//! ```
//! # fn main() {
//! # #[cfg(feature = "logwise")]
//! # {
//! #[derive(Debug)]
//! struct ComplexData {
//! value: i32
//! }
//!
//! let data = ComplexData { value: 42 };
//!
//! // Complex types need to be wrapped with LogIt for privacy control
//! // This demonstrates the syntax, though actual capture requires begin_capture()
//! // logwise::info_sync!(
//! // "Processing data: {data}",
//! // data = logwise::privacy::LogIt(&data)
//! // );
//! # }
//! # }
//! ```
//!
//! # Privacy Considerations
//!
//! The logwise framework includes a dual logging system with privacy controls.
//! When using this module, be aware that:
//! - All captured logs are forwarded to external systems
//! - Sensitive data should use appropriate logwise privacy wrappers
//! - The forwarding respects logwise's privacy settings and redaction rules
use crateInternalProxy;
use crateNotification;
use ;
use Future;
use Pin;
use Arc;
/// A logger implementation that forwards log records through the exfiltrate system.
///
/// This logger intercepts logwise log records and converts them to JSON-RPC
/// notifications that are sent through the internal proxy. This allows external
/// systems to receive and process log data in real-time.
///
/// # Implementation Details
///
/// The logger implements both synchronous and asynchronous logging methods,
/// though both currently use the same underlying synchronous implementation
/// for simplicity and consistency.
/// Begins capturing logwise log records for forwarding through exfiltrate.
///
/// This function installs a custom logger that intercepts all logwise log records
/// and forwards them as JSON-RPC notifications through the internal proxy system.
/// This allows external systems to receive and process log data.
///
/// # Effects
///
/// After calling this function:
/// - All logwise log records will be captured and forwarded
/// - A notification is sent indicating log capture has started
/// - A message is printed to stderr confirming capture has begun
///
/// # Thread Safety
///
/// This function can be called from any thread, but should typically only be
/// called once at application startup. Multiple calls are safe but will result
/// in duplicate log forwarding.
///
/// # Examples
///
/// ## Basic initialization
///
/// ```
/// # fn main() {
/// # #[cfg(feature = "logwise")]
/// # {
/// // Start capturing logs at application startup
/// // Note: This would actually start capture in a real application
/// // exfiltrate::logwise::begin_capture();
///
/// // All subsequent logwise logs would be forwarded
/// // logwise::info_sync!("Application started");
/// // logwise::debug_sync!("Debug mode enabled", verbose=true);
/// # }
/// # }
/// ```
///
/// ## With error handling
///
/// ```
/// # fn main() {
/// # #[cfg(feature = "logwise")]
/// # {
/// use std::fs::File;
/// use std::io::Error;
///
/// // In a real application, you would call:
/// // exfiltrate::logwise::begin_capture();
///
/// match File::open("nonexistent.json") {
/// Ok(_) => {
/// // logwise::info_sync!("Config loaded successfully")
/// },
/// Err(e) => {
/// // logwise::error_sync!("Failed to load config: {error}", error=e.to_string())
/// },
/// }
/// # }
/// # }
/// ```
///
/// ## Integration pattern
///
/// ```
/// # fn main() {
/// # #[cfg(feature = "logwise")]
/// # {
/// // Example of how to structure log capture initialization
/// fn initialize_logging() {
/// // This would be called early in your application:
/// // exfiltrate::logwise::begin_capture();
///
/// // Then you can use logwise macros throughout your code:
/// // logwise::info_sync!("Logging system initialized");
/// }
///
/// // Call at application startup
/// initialize_logging();
/// # }
/// # }
/// ```