logger.scm 860 B

123456789101112131415161718192021222324252627282930
  1. (library (lib logger)
  2. (export debug info warning error make-prefixed-log-proc)
  3. (import
  4. (except (rnrs base) let-values map error)
  5. (only (guile)
  6. lambda* λ
  7. simple-format
  8. current-output-port
  9. call-with-output-string)
  10. (ice-9 textual-ports)
  11. (lib string-procs)))
  12. (define log-prefixed
  13. (lambda* (str prefix #:optional (output-port (current-output-port)))
  14. (put-string output-port
  15. (string-format "~a: ~a\n" prefix str))))
  16. (define make-prefixed-log-proc
  17. (λ (the-prefix)
  18. (lambda* (str #:optional (output-port (current-output-port)))
  19. (log-prefixed str the-prefix output-port))))
  20. (define debug (make-prefixed-log-proc "DEBUG"))
  21. (define info (make-prefixed-log-proc "INFO"))
  22. (define warning (make-prefixed-log-proc "WARNING"))
  23. (define error (make-prefixed-log-proc "ERROR"))