Added a store to simple-log.

This commit is contained in:
2026-08-03 10:17:17 +02:00
parent 07cf44a098
commit 5869df9f59
3 changed files with 220 additions and 6 deletions
+23 -6
View File
@@ -5,16 +5,20 @@
racket-sprintf
racket/async-channel
data/queue
"private/loghash.rkt"
"private/store.rkt"
)
(provide sl-def-log
sl-log-to
sl-log-to-file
sl-log-to-display
sl-log-to-store
sl-log-to-file&display
sl-set-log-level
sl-log-level
sl-sync
(all-from-out "private/store.rkt")
)
(define (iso-timestamp)
@@ -72,11 +76,7 @@
(define (sl-log-level)
log-level)
(define log-hash (hash 'debug 0 'dbg 0
'info 1
'warning 2 'warn 2
'err 3 'error 3
'fatal 5))
(define (needs-logging level)
(let ((ll (hash-ref log-hash log-level 6))
@@ -189,6 +189,14 @@
(dbg-simple-log "log-to-display enabled")
)
(define (sl-log-to-store [max-length 1000])
(let ((st (make-sl-store max-length)))
(sl-log-to store
(λ (topic level dt msg)
(sl-store-enqueue! st topic level dt msg)))
(dbg-simple-log "log to store enabled")
st))
(define (log-to-file* filename)
(let ((out (open-output-file filename #:exists 'replace)))
(sl-log-to file (λ (topic level dt msg)
@@ -250,4 +258,13 @@
(sl-def-log simple-log)
(define (sl-store-test)
(sl-def-log test)
(dbg-test "Dit is debug bericht 1")
(info-test "Dit is info bericht 1")
(info-test "Dit is info bericht 2")
(err-test "Dit is een foutbericht")
(err-test "Dit is nog een foutbericht")
(fatal-test "JA!")
(dbg-test "Oke, nog een debug bericht")
)