summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-07-26 20:15:03 +0200
committerYves Fischer <yvesf-git@xapek.org>2014-07-26 20:15:03 +0200
commit99c6eb21eb7ff9a072b87d9d64324871ea7201f1 (patch)
treea10f6469ce898d518955ee85cf367c8a2af77b29
parent773093acabfb84b88c37bb0342d6a8d4a6f8267a (diff)
downloadebus-alt-99c6eb21eb7ff9a072b87d9d64324871ea7201f1.tar.gz
ebus-alt-99c6eb21eb7ff9a072b87d9d64324871ea7201f1.zip
fix logging, re-enable dumper layer7 output
-rwxr-xr-xebus-racket/dumper.rkt17
-rw-r--r--ebus-racket/ebus/layer2.rkt6
-rw-r--r--ebus-racket/ebus/layer7.rkt10
-rwxr-xr-xebus-racket/inserter.rkt23
4 files changed, 32 insertions, 24 deletions
diff --git a/ebus-racket/dumper.rkt b/ebus-racket/dumper.rkt
index 62ca64e..95081d1 100755
--- a/ebus-racket/dumper.rkt
+++ b/ebus-racket/dumper.rkt
@@ -1,10 +1,11 @@
#! /usr/bin/env racket
#lang racket/base
-(require racket/cmdline
- racket/tcp
- racket/pretty
- "ebus/layer2.rkt"
- "ebus/layer7.rkt")
+(require
+ racket/cmdline
+ racket/tcp
+ racket/pretty
+ "ebus/layer2.rkt"
+ "ebus/layer7.rkt")
;(define verbose? (make-parameter #f))
(define connect-host? (make-parameter null))
@@ -38,9 +39,9 @@
(define (read-ebus-loop7 input-port)
(let ([fields (layer7-read-ebus (current-input-port))])
- ;(if (not (void? fields))
- ;(pretty-print fields)
- ;(display ""))
+ (if (not (void? fields))
+ (pretty-print fields)
+ (display ""))
(cond ((not (eof-object? fields)) (read-ebus-loop7 input-port)))))
(if (layer7?)
diff --git a/ebus-racket/ebus/layer2.rkt b/ebus-racket/ebus/layer2.rkt
index 3309c16..192f7f5 100644
--- a/ebus-racket/ebus/layer2.rkt
+++ b/ebus-racket/ebus/layer2.rkt
@@ -3,6 +3,8 @@
(planet bzlib/parseq:1:3))
(define logger (make-logger 'ebus-layer2 (current-logger)))
+(current-logger logger)
+
;; Ebus SYN
(define ebus-const-syn #xaa)
;; Ebus Escape-Sequence Start
@@ -83,7 +85,7 @@
(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-message logger 'debug (format "drop ~s x SYN (~s)" syn ebus-const-syn) #t)))
+ (log-debug "drop ~s x SYN (~s)" syn ebus-const-syn)))
(cond ((not (false? paket))
paket)
((eof-object? (peek-byte input-port))
@@ -91,7 +93,7 @@
(else
;; skip one byte
(let ([byte (read-byte input-port)])
- (log-message logger 'debug (format "drop ~s 0x~x" byte byte) #t))
+ (log-debug "drop ~s 0x~x" byte byte))
(read-ebus input-port))))
(provide
diff --git a/ebus-racket/ebus/layer7.rkt b/ebus-racket/ebus/layer7.rkt
index c7fb228..60f8bbc 100644
--- a/ebus-racket/ebus/layer7.rkt
+++ b/ebus-racket/ebus/layer7.rkt
@@ -7,6 +7,7 @@
"layer2.rkt")
(define logger (make-logger 'ebus-layer7 (current-logger)))
+(current-logger logger)
(define definition
(parameterize ([collapse-whitespace #t]
@@ -16,6 +17,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)
(xexpr-path-first (list 'packets 'packet (list 'primary primaryCommand)
(list 'secondary secondaryCommand)) definition))
@@ -44,8 +46,10 @@
(define payload (layer2-ebus-paket-payload ebus-paket))
(for/list ([decoder decoders])
(decoder payload)))
- (else (void (log-message logger 'warning
- (format "Unknown Paket from source ~s: ~s" (layer2-ebus-paket-source ebus-paket) ebus-paket) #t)))))
+ (else (void (log-info "Unknown Paket from source ~s(~s): ~s"
+ (layer2-ebus-paket-source ebus-paket)
+ source-device-name
+ ebus-paket)))))
(define (create-decoder paket-id field)
@@ -53,7 +57,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-message logger 'warning (format "No decoder for type ~s" type) #t)))
+ (cond ((false? decoder) (void (log-warning "No decoder for type ~s" type)))
(else (curry (car decoder) name field offset))))
(define decoder-table
diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt
index cd05ad9..90ae258 100755
--- a/ebus-racket/inserter.rkt
+++ b/ebus-racket/inserter.rkt
@@ -9,6 +9,7 @@
"util/json.rkt")
(define logger (make-logger 'ebus-inserter (current-logger)))
+(current-logger logger)
(define connect-host? (make-parameter null))
(define connect-port? (make-parameter null))
@@ -28,21 +29,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-message logger 'debug (format "Successful insert: type=~a value=~a"
- type value) #t))
- (else (log-message logger 'error (format "Error: type=~a value=~a ERROR:~a"
- type value response) #t))))
+ (log-debug "Successful insert: type=~a value=~a"
+ type value))
+ (else (log-error "Error: type=~a value=~a ERROR:~a"
+ type value response))))
(define (handle-packet packet)
(for ([field packet])
- (log-message logger 'info (format "Field: ~a" field) #t)
+ (log-info "Field: ~a" field)
(when (insert?)
(with-handlers ([exn:fail? (lambda (exn)
- (log-message logger 'error (format "Failed to insert ~a: ~a" field exn) #t))]
+ (log-error "Failed to insert ~a: ~a" field exn))]
[exn:fail:read? (lambda (exn)
- (log-message logger 'error (format "TCP Read exception ~a" exn) #t))]
+ (log-error "TCP Read exception ~a" exn))]
[exn:fail:network? (lambda (exn)
- (log-message logger 'error (format "TCP Exception ~a" exn) #t))])
+ (log-error "TCP Exception ~a" exn))])
(apply insert-field field)))))
(define-namespace-anchor repl-ns-anchor)
@@ -63,9 +64,9 @@
;; Connect, replacing input with tcp connection
(if (or (null? (connect-host?)) (null? (connect-port?)))
- (log-message (current-logger) 'info "Using stdin" #t)
+ (log-info "Using stdin")
(let-values ([(cin cout) (tcp-connect (connect-host?) (connect-port?))])
- (log-message logger 'info (format "Connected to ~s ~s ~n" (connect-host?) (connect-port?)) #t)
+ (log-info "Connected to ~s ~s ~n" (connect-host?) (connect-port?))
(current-input-port cin)))
;; Process Ebus Packets
@@ -77,7 +78,7 @@
(define (make-stream port)
(stream-cons (with-handlers ([exn:fail? (lambda (exn)
- (log-message logger 'error (format "Failed to parse paket: ~a" exn) #t)
+ (log-error "Failed to parse paket: ~a" exn)
(void))])
(layer7-read-ebus port))
(make-stream port)))