diff options
Diffstat (limited to 'ebus-racket')
-rw-r--r-- | ebus-racket/ebus/layer2.rkt | 17 | ||||
-rw-r--r-- | ebus-racket/ebus/layer7.rkt | 14 | ||||
-rwxr-xr-x | ebus-racket/inserter.rkt | 21 |
3 files changed, 22 insertions, 30 deletions
diff --git a/ebus-racket/ebus/layer2.rkt b/ebus-racket/ebus/layer2.rkt index 192f7f5..3141452 100644 --- a/ebus-racket/ebus/layer2.rkt +++ b/ebus-racket/ebus/layer2.rkt @@ -2,8 +2,7 @@ (require racket/bool (planet bzlib/parseq:1:3)) -(define logger (make-logger 'ebus-layer2 (current-logger))) -(current-logger logger) +(define-logger ebus2) ;; Ebus SYN (define ebus-const-syn #xaa) @@ -84,16 +83,13 @@ (define (read-ebus input-port) (define syn ((make-reader ebus-sync #:sof? #f #:eof? #f) input-port)) (define paket ((make-reader parse-ebus-paket #:sof? #f #:eof? #f) input-port)) - (cond ((not (false? syn)) - (log-debug "drop ~s x SYN (~s)" syn ebus-const-syn))) - (cond ((not (false? paket)) - paket) - ((eof-object? (peek-byte input-port)) - eof) + (cond ((not (false? syn)) (log-ebus2-debug "dropped ~a x SYN (~a)" syn ebus-const-syn))) + (cond ((not (false? paket)) paket) + ((eof-object? (peek-byte input-port)) eof) (else ;; skip one byte (let ([byte (read-byte input-port)]) - (log-debug "drop ~s 0x~x" byte byte)) + (log-ebus2-debug "drop ~s 0x~x" byte byte)) (read-ebus input-port)))) (provide @@ -102,5 +98,4 @@ (prefix-out layer2- (struct-out ebus-paket)) (prefix-out layer2- (struct-out ebus-body-broadcast)) (prefix-out layer2- (struct-out ebus-body-mastermaster)) - (prefix-out layer2- (struct-out ebus-body-masterslave)) - (prefix-out layer2- logger)) + (prefix-out layer2- (struct-out ebus-body-masterslave))) diff --git a/ebus-racket/ebus/layer7.rkt b/ebus-racket/ebus/layer7.rkt index 60f8bbc..76ea6ae 100644 --- a/ebus-racket/ebus/layer7.rkt +++ b/ebus-racket/ebus/layer7.rkt @@ -6,8 +6,7 @@ "xexpr-path/main.rkt" "layer2.rkt") -(define logger (make-logger 'ebus-layer7 (current-logger))) -(current-logger logger) +(define-logger ebus7) (define definition (parameterize ([collapse-whitespace #t] @@ -17,7 +16,7 @@ (define (paket ebus-paket) (define primaryCommand (number->string (layer2-ebus-paket-primaryCommand ebus-paket))) (define secondaryCommand (number->string (layer2-ebus-paket-secondaryCommand ebus-paket))) - (log-debug "Lookup paket primaryCommand=~a secondaryCommand=~a" primaryCommand secondaryCommand) + (log-ebus7-debug "Lookup paket primaryCommand=~a secondaryCommand=~a" primaryCommand secondaryCommand) (xexpr-path-first (list 'packets 'packet (list 'primary primaryCommand) (list 'secondary secondaryCommand)) definition)) @@ -46,7 +45,7 @@ (define payload (layer2-ebus-paket-payload ebus-paket)) (for/list ([decoder decoders]) (decoder payload))) - (else (void (log-info "Unknown Paket from source ~s(~s): ~s" + (else (void (log-ebus7-info "Unknown Paket from source ~s(~s): ~s" (layer2-ebus-paket-source ebus-paket) source-device-name ebus-paket))))) @@ -57,7 +56,7 @@ (define name (string-append paket-id "." (xexpr-path-first '((name)) field))) (define offset (string->number (xexpr-path-first '((offset)) field))) (define decoder (hash-ref decoder-table type #f)) - (cond ((false? decoder) (void (log-warning "No decoder for type ~s" type))) + (cond ((false? decoder) (void (log-ebus7-warning "No decoder for type ~s" type))) (else (curry (car decoder) name field offset)))) (define decoder-table @@ -168,6 +167,5 @@ (prefix-out layer7- device) (prefix-out layer7- device-name) (prefix-out layer7- definition) - ;; read ebus from port an return fields from next paket - (prefix-out layer7- read-ebus) - (prefix-out layer7- logger)) + ;; read ebus from port an return fields from next paket + (prefix-out layer7- read-ebus)) diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt index 90ae258..ab97ecf 100755 --- a/ebus-racket/inserter.rkt +++ b/ebus-racket/inserter.rkt @@ -8,8 +8,7 @@ "util/tcp-repl.rkt" "util/json.rkt") -(define logger (make-logger 'ebus-inserter (current-logger))) -(current-logger logger) +(define-logger inserter) (define connect-host? (make-parameter null)) (define connect-port? (make-parameter null)) @@ -29,21 +28,21 @@ (string->bytes/utf-8 (format "value=~a&type=~a" value type))))) (define responseJson (string->jsexpr response)) (cond ((eq? (json-null) (hash-ref responseJson 'error)) - (log-debug "Successful insert: type=~a value=~a" + (log-inserter-debug "Successful insert: type=~a value=~a" type value)) - (else (log-error "Error: type=~a value=~a ERROR:~a" + (else (log-inserter-error "Error: type=~a value=~a ERROR:~a" type value response)))) (define (handle-packet packet) (for ([field packet]) - (log-info "Field: ~a" field) + (log-inserter-info "Field: ~a" field) (when (insert?) (with-handlers ([exn:fail? (lambda (exn) - (log-error "Failed to insert ~a: ~a" field exn))] + (log-inserter-error "Failed to insert ~a: ~a" field exn))] [exn:fail:read? (lambda (exn) - (log-error "TCP Read exception ~a" exn))] + (log-inserter-error "TCP Read exception ~a" exn))] [exn:fail:network? (lambda (exn) - (log-error "TCP Exception ~a" exn))]) + (log-inserter-error "TCP Exception ~a" exn))]) (apply insert-field field))))) (define-namespace-anchor repl-ns-anchor) @@ -64,9 +63,9 @@ ;; Connect, replacing input with tcp connection (if (or (null? (connect-host?)) (null? (connect-port?))) - (log-info "Using stdin") + (log-inserter-info "Using stdin") (let-values ([(cin cout) (tcp-connect (connect-host?) (connect-port?))]) - (log-info "Connected to ~s ~s ~n" (connect-host?) (connect-port?)) + (log-inserter-info "Connected to ~s ~s ~n" (connect-host?) (connect-port?)) (current-input-port cin))) ;; Process Ebus Packets @@ -78,7 +77,7 @@ (define (make-stream port) (stream-cons (with-handlers ([exn:fail? (lambda (exn) - (log-error "Failed to parse paket: ~a" exn) + (log-inserter-error "Failed to parse paket: ~a" exn) (void))]) (layer7-read-ebus port)) (make-stream port))) |