mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-17 09:57:34 +02:00
portability fixes for (chibi log)
This commit is contained in:
parent
6b5c2c3d0b
commit
70c85542e2
2 changed files with 16 additions and 9 deletions
|
@ -63,7 +63,7 @@
|
|||
(define (log-normalize-name name)
|
||||
(let ((str (symbol->string name)))
|
||||
(if (string-prefix? "log-" str)
|
||||
(string->symbol (substring str 4))
|
||||
(string->symbol (substring str 4 (string-length str)))
|
||||
name)))
|
||||
|
||||
(define (log-level-index logger level)
|
||||
|
@ -115,8 +115,8 @@
|
|||
(message (show #f (each-in-list args))))
|
||||
(string-append
|
||||
prefix
|
||||
(string-concatenate (string-split message #\newline)
|
||||
(string-append "\n" prefix))
|
||||
(string-join (string-split message #\newline)
|
||||
(string-append "\n" prefix))
|
||||
"\n")))
|
||||
|
||||
(define (log-compile-prefix spec)
|
||||
|
@ -148,7 +148,7 @@
|
|||
(let ((time (seconds->time (current-seconds))))
|
||||
(let lp ((ls procs) (res '()))
|
||||
(if (null? ls)
|
||||
(string-concatenate (reverse res))
|
||||
(string-join (reverse res))
|
||||
(lp (cdr ls) (cons ((car ls) logger time level) res))))))))
|
||||
|
||||
(define log-default-prefix
|
||||
|
@ -162,7 +162,8 @@
|
|||
(logger-port-set! logger (current-error-port))))
|
||||
|
||||
(define (log-close logger)
|
||||
(if (output-port? (logger-port logger))
|
||||
(if (and (output-port? (logger-port logger))
|
||||
(not (eq? (current-error-port) (logger-port logger))))
|
||||
(close-output-port (logger-port logger))))
|
||||
|
||||
;; Use file-locking to let multiple processes write to the same log
|
||||
|
@ -185,13 +186,13 @@
|
|||
(log-open logger)
|
||||
(lp #f))
|
||||
(else ; fall back to stderr
|
||||
(display str (current-error-port))))))
|
||||
(write-string str (current-error-port))))))
|
||||
(let ((locked? (and (logger-locked? logger)
|
||||
(output-port? out)
|
||||
(file-lock out lock/exclusive))))
|
||||
;; this is redundant with POSIX O_APPEND
|
||||
;; (set-file-position! out 0 seek/end)
|
||||
(display str out)
|
||||
(write-string str out)
|
||||
(flush-output out)
|
||||
(if locked? (file-lock out lock/unlock))))))))))
|
||||
|
||||
|
|
|
@ -24,16 +24,22 @@
|
|||
(import (chibi time) (chibi string) (chibi show base))
|
||||
(cond-expand
|
||||
(chibi
|
||||
(import (chibi) (chibi filesystem) (chibi process) (chibi system) (srfi 9))
|
||||
(import (chibi) (chibi filesystem) (chibi process) (chibi string)
|
||||
(chibi system) (srfi 9))
|
||||
(begin
|
||||
(define write-string display)
|
||||
(define (open-output-file/append path)
|
||||
(let ((fd (open path
|
||||
(+ open/create open/write open/append open/non-block))))
|
||||
(open-output-file-descriptor fd)))))
|
||||
(else
|
||||
(import (scheme base))
|
||||
(import (scheme base) (scheme char) (scheme file) (chibi string))
|
||||
(begin
|
||||
(define-syntax protect
|
||||
(syntax-rules ()
|
||||
((protect . x) (guard . x))))
|
||||
(define open-output-file/append open-output-file)
|
||||
(define flush-output flush-output-port)
|
||||
(define (file-lock port-or-fileno mode) 'unsupported)
|
||||
(define lock/exclusive 'unsupported)
|
||||
(define lock/unlock 'unsupported)
|
||||
|
|
Loading…
Add table
Reference in a new issue