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
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Log record type for the logwise logging system.
//!
//! This module defines [`LogRecord`], the core data structure that accumulates log message
//! parts during the logging process. Log records are built incrementally using the `log`
//! and `log_owned` methods, then submitted to loggers for output.
//!
//! # Design Philosophy
//!
//! The `LogRecord` type is designed to minimize allocations during logging. Instead of
//! concatenating strings, it stores parts separately and only joins them when needed for
//! final output. This approach:
//!
//! - Reduces memory allocation overhead
//! - Enables efficient pass-by-value to loggers
//! - Supports thread-safe logging without shared buffers
//!
//! # Usage Pattern
//!
//! 1. Create a new `LogRecord` with a log level
//! 2. Progressively add message parts using `log()` or `log_owned()`
//! 3. Submit the complete record to loggers via `Logger::finish_log_record()`
//!
//! # Example
//!
//! ```rust
//! use logwise::{LogRecord, Level};
//!
//! // Create a new record
//! let mut record = LogRecord::new(Level::Info);
//!
//! // Add message parts
//! record.log("Processing request ");
//! record.log_owned(format!("#{}", 42));
//! record.log(" completed");
//!
//! // The record can now be sent to loggers
//! // println!("{}", record); // Output: "Processing request #42 completed"
//! ```
use crateLevel;
use ;
use OnceLock;
static INITIAL_TIMESTAMP: = new;
/**
A log record.
We'd like to construct our API in a way that we don't need to allocate memory by concatenating strings, etc.
So instead our API assumes you progressively write a lot into somewhere. However, due to the multithreaded
nature of logging, we need to be able to write to a buffer that is not shared between threads.
Instead, the design is as follows:
1. Create a new [LogRecord].
2. Progressively write to the [LogRecord].
3. Finish the [LogRecord] and submit it to the [logwise::logger::Logger].
*/
/*
Boilerplate notes for LogRecord:
IMPLEMENTED:
- Debug: Derived - essential for diagnostics
- Clone: Derived - useful for record duplication/forwarding
- PartialEq/Eq: Derived - enables record comparison and deduplication
- Hash: Derived - consistent with Eq, enables use in hash collections
- Default: Implemented - provides sensible zero-value (Info level, empty parts)
- Display: Implemented - formats record parts for output
NOT IMPLEMENTED:
- Copy: Vec<String> contains heap-allocated data, not suitable for Copy
- Ord/PartialOrd: No meaningful ordering for log records
- From/Into: No obvious conversions to/from other types
- AsRef/AsMut: No clear underlying type to reference
- Deref: Must deref to a pointer type, which LogRecord doesn't naturally provide
AUTOMATIC:
- Send: Automatically implemented - Vec<String> and Level are Send
- Sync: NOT automatically implemented - Vec<String> is not Sync (but records
are typically owned by single threads during construction anyway)
*/