-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogging.txt
More file actions
473 lines (353 loc) · 10.1 KB
/
logging.txt
File metadata and controls
473 lines (353 loc) · 10.1 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
Logging
Levels: E, W, M, 1 2 3 4 5
Error, Warning, Message (Info)
plus 5 debugging levels
Output:
stderr
curses
queued
file
Attrs:
timestamp
file
line
function
level
format
args...
error(fmt, args...)
message()
warning()
debug()
all #defines to log_dispatcher (a function variable)
log_dispatcher -> dispatcher_curses()
dispatcher_curses()
error -> file, screen
message -> file, screen
debug -> file
dispatcher_file() if enabled
write to file
optionally flush after every
error
n messages
n seconds
where does the timestamp originate?
where does the debug level filtering occur?
probably in dispatcher_file()
multiple dispatchers
if logging is disabled, then keep a small ring of messages
dispatch_curses -> screen
dispatch_file -> disk
dispatch_queue -> memory
dispatch_stderr -> stderr
all dispatch functions to take all params
flush_queue(dispatch_function)
rename .neomuttdebug -> .neomutt_log?
easier to display backlog if messages are *always* written to disk
neomutt -d0 (or absent) => only write M, W, E to disk
:messages show file verbatim
could colour code according to error/info colours
need to save in a parsable way, e.g. <E>, <3>
macros pass 0 for time
disp_queue saves now()
flushq passes saved time
debug macro passes file, line, func
others pass NULL
M,W,E and D macros pass level, fmt, args
if no log file, create tmp, populate from ring and display in pager
migrate debugging -> logging
LogLevel 0..5
LogFile file (template) or % expandos
LogKeep 5?
once started we can't know the log's filename
(could be renamed by other instances)
expandos for template
%p pid
%t time (HH:MM) :SS?
%d date (YYYY-MM-DD)
expand other stuff too?
$config vars?
$ENV vars?
variable is only expanded and checked when set
=> no new logfile at midnight
what's preventing LOTS of logfiles?
check for locks (actively used)
check for date (stat) > 1 week?, 1 month?
means we need a dedicated log *DIR*
need to scan dir for files
if there are zero expandos (or variables)
then rotate up to 5 files
otherwise
!exists - create
exists - append
accumulate lots of files, up to user to clear them
default to ~/.neomutt/logs/log
default location means we could syntax highlight
error,warning,message,debug (grey for levels 3,4,5)
variable/config ownership
lib
DebugFile, set_file()
DebugLevel, set_level()
FILE*
actual filename/level aren't needed
mutt
Initial file
Initial level
for reset
Logging bug
Leave mutt running, then
start/close mutt 5 times
log file of running mutt has been deleted
use file locking on logs to prevent overwriting
or premature deletion
option in :messages page to save the text
default log level to -1
level 0 logs msg/error
stderr ignores progress message (or same magic filtering)
abstract progress into separate file
progress - [%d messages omitted]
need to keep count
mutt_logging:
start,stop,file,level,rotate,disp_curses
mutt/logging:
open,close,ver,file,level
states: disabled, enabled, level m, level n
startup
startup -> queue
parse command line -> logging
quick stuff -v, -D, etc flush and exit
mutt_init -> config -> logging, flush, exit OR
start_logging(ver, file, level)
options
{cmdline,config,none} . {-d,-l}
6 possibilities just to get to start_logging()
plus test -v, -D routes
while running file,level0, leveln, file2
level-n -> level-n+1 (Now @ level n+1)
level-n -> level0 (keep file open, but not output?)
no close file
level0 -> level-n (Now @ level n) (for open file)
level0 -> level-n (no file) open file, Now @ level n
setting file, cmdline or config occur before start_logging()
therefore log is enabled or disabled
disabled -> enabled : rotate, openfile
enabled -> disabled : close (only on exit)
enabled -> enabled (new file) : close, rotate, open
new levels: progress (bar), text (preceded by msg/error?)
PEWMBT12345, perror, error, warning, message, bar, text, d1, d2, d3, d4, d5
progress rules -> log contains mix of M and B (progress)
M B0 {B1-21 elided} B22 M B23 {B24-98 elided} B99 M
text rules => M T T T T
file might <tab> indent lines
indent prevents confusion with other lines
perror, print errno(int) too?
progress: curses: YES, stderr, file: MAGIC filter
text: curses: NO, stderr, file: dependent on previous line
move {read,write,net,time}_inc into curses_message?
Q:
colours or no colours?
for curses
for terminal
default binding?
problem:
files are rotated even if logging isn't enabled
on startup main() calls mutt_write_address_list() -> stdout
separate address from output
use level 0 for info messages -- always logged?
does curses_message() still show up in the logs?
special level for progress messages
hard when they're interleaved with other debugging messages
turn message log into fake mailbox
set pager_index_lines = 10
index shows lines (short)
pager shows full text, laid out
log file rotation is happening when logging isn't enabled
mutt_exit -> atexit -> endwin
ErrorBuf?
log_file_close
no sleep
no "press any key to continue"
log_close(quiet)
mutt_query_exit() !! from SIGINT
all perror -> mutt_perror()
atexit -> lots of unique retvals
document current use of retvals
document all exits from neomutt
can we uses curses keywait without refresh? NO
e.g. create ~/Mail
mutt_query_exit -> call mutt_exit
mutt_exit -> macro need to know *where* it died
if logq, flush it, dump to screen, backtrace if available
eliminate fprintf for errors
put everything through the mutt_{debug,message,error}
mechanism
debug in curses_message() gives misleading function name
define MIN/MAX debug levels and test against these
logging
print date, then just time for log lines
debug_level > n => fflush every line
or after every 'n' seconds
mutt_log -> level 1 ==
mutt_message
mutt_error
or == level 0
mutt_debug -> level 2+
need audit
263 mutt_message
728 mutt_error
704 mutt_debug (total ~1700)
enable debug from within mutt
set debuglevel
set debugfile
rotate files?
mutt_exit() -> (retval, msg)
e.g. function name
all message handlers
save and restore errno
doxy doc this
categorise all messages in code
info, warning, error, question
which imply user to do: nothing, be informed, worry, query user
errors should be clear whose fault
user: e.g. type something invalid
config: file invalid / missing
code: internal error, missing ops
separate what user cannot do vs MAY not do
------------------------------------------------------------
idea for Level 1 debugging: **User actions log**
Every action the user makes, "Compose Email", "Send email", "Open mailbox" should be logged at level 1.
This should include any hooks that they've set up.
If the user was in the pager, we wouldn't log the keypress, <kbd>j</kbd>, but we would log "Open message".
This level should always be saved to the internal message log.
------------------------------------------------------------
main()top
logq
getopt
if 'v'
flush(stderr)
exit
read_config
if 'D'
flush(stderr)
exit
** DebugFile
** DebugLevel
start_debug(file,level)
flush(curses)
main_loop()
stop_debug()
exit
------------------------------------------------------------
start_debug(file,level)
expand_file(file)
rotate_files()
log_level(level)
log_open(file0)
------------------------------------------------------------
log_level(level)
static level = 9
if (level changes) & (level != 9)
set level
debug("logging at level %d")
------------------------------------------------------------
log_open(file)
static file = ""
if file changed
empty -> empty
do nothing
empty -> name
create file / append
log "starting"
is this my job?
don't know the version
name -> empty
log "closing"
close file
name -> name (same)
do nothing
name -> name (diff)
log "closing"
close old
open new
log "opening"
------------------------------------------------------------
stop_debug()
log_stderr
log_close
------------------------------------------------------------
log_close
log "closing"
close file
file=""
------------------------------------------------------------
FILE debug/error()
if (lev <= dlev) && (file open)
write to file
------------------------------------------------------------
CURSES debug/error()
FILE_debug() duplicate
normal screen stuff
------------------------------------------------------------
STDERR debug/error()
if (lev <= dlev) && (file open)
write to stderr
------------------------------------------------------------
QUEUE debug/error()
save to Q
------------------------------------------------------------
*Were* messages saved to ErrorBuf, before or just errors?
YES messages were
----
Testing
set version
rotate logs
set filename
set level
CLI Config
- -
-d -d
-l -l
-d,-l -d,-l
log level ∀ config changes?
logging - extend 2 second rule by logging level
l2 message overwrites a l3 message
l3 message is blocked a l2 message
mutt_log(Buffer) -> split at \n
multiple logs
what level (all at same?)
on segfault, log backtrace to logfile too
logging - take a Buffer param
do we log questions? (and their answers?)
neomutt log add startup timings
use log's timestamp
or measure our own millisecond timings
separate logging from libmutt?
register "sensitive" regexes in the logger
e.g. AUTHENTICATE
could some log levels share level numbers
NO, can't distinguish them later for labels
unless 400, 401, 402 are all level 4
log level ∀ file operations
create/del/link/lock/etc
caller's id?
log the FD of open/close and other file ops
debug log
use file locking
find first missing file, or oldest unlocked
logging file -- does it expand "~" mutt_expand_path
a) cmdline options
b) config options
don't log (to file) UI messages like "you are on last message"
need new log level
logging ideas
audit the levels
add sensitive logging option
remove logging levels completely
debug logging
use millisecond timestamps?
log before regex ops & other risky functions
promote logging to default -- too useful
set max level?
- 242 `mutt_message()` - Informational messages
- 38 `mutt_warning()` - Warning messages - Something went wrong, but we can explain to the user what went wrong and why.
- 595 `mutt_error()` - Error messages - Something went wrong, but it's not clear what the user could have done differently.