From b79a5a8ab011e8b4ee3a9adb3b1085a6acd0f482 Mon Sep 17 00:00:00 2001 From: Random Hacker Date: Tue, 6 Mar 2012 15:43:32 +0100 Subject: ebus-racket: set db-default loglevel=warning; add exception handler in inserter --- ebus-racket/inserter.rkt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'ebus-racket') diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt index bd23e04..ab90911 100755 --- a/ebus-racket/inserter.rkt +++ b/ebus-racket/inserter.rkt @@ -13,23 +13,27 @@ (define connect-host? (make-parameter null)) (define connect-port? (make-parameter null)) (define loglevel-layer2? (make-parameter 'info)) -(define loglevel-db? (make-parameter 'info)) +(define loglevel-db? (make-parameter 'warning)) (define insert? (make-parameter #f)) (define (handle-fields fields) (for ([field fields]) (log-message logger 'info (format "Field: ~a" field) #t) (when (insert?) - (apply db-insert-field field)))) + (with-handlers ([exn:fail? (lambda (exn) + (log-message logger 'error (format "Failed to insert ~a: ~a" field exn) #t))]) + (apply db-insert-field field))))) (define (make-ebus-loop7 input-port) (lambda () (let loop () - (let ([fields (layer7-read-ebus (current-input-port))]) - (when (not (or (void? fields) (eof-object? fields))) - (handle-fields fields)) - (when (not (eof-object? fields)) - (loop)))))) + (with-handlers ([exn:fail? (lambda (exn) + (log-message logger 'error (format "Failed to parse paket: ~a" exn) #t))]) + (let ([fields (layer7-read-ebus (current-input-port))]) + (when (not (or (void? fields) (eof-object? fields))) + (handle-fields fields)) + (when (not (eof-object? fields)) + (loop))))))) ;; Start Thread that observe all given log-receivers (define (start-logger-thread receiver1 . receiverN) -- cgit v1.2.1