From 8a9d96086ca3e1bf73001f8fdd32c5431668baf3 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Sun, 6 Oct 2013 00:10:55 +0000 Subject: [PATCH] code/imports cleanup --- go/door_daemon_zmq/main.go | 32 ++++++++++---------------------- go/door_daemon_zmq/serial_tty.go | 8 +++----- go/r3-netstatus/main.go | 2 +- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/go/door_daemon_zmq/main.go b/go/door_daemon_zmq/main.go index 606c364..32096d7 100644 --- a/go/door_daemon_zmq/main.go +++ b/go/door_daemon_zmq/main.go @@ -3,12 +3,9 @@ package main import ( - "fmt" "os" "flag" "time" - "log/syslog" - "log" ) //~ func StringArrayToByteArray(ss []string) [][]byte { @@ -25,19 +22,25 @@ var ( cmd_port_ string pub_port_ string door_tty_path_ string - use_syslog_ bool - Syslog_ *log.Logger + enable_syslog_ bool + enable_debug_ bool ) func init() { flag.StringVar(&cmd_port_, "cmdport", "ipc:///run/tuer/door_cmd.ipc", "zmq command socket path") flag.StringVar(&pub_port_, "pubport", "tcp://*:4242", "zmq public/listen socket path") flag.StringVar(&door_tty_path_, "device", "/dev/door", "door tty device path") - flag.BoolVar(&use_syslog_, "syslog", false, "log to syslog local1 facility") + flag.BoolVar(&enable_syslog_, "syslog", false, "enable logging to syslog") + flag.BoolVar(&enable_debug_, "debug", false, "enable debug output") flag.Parse() } func main() { + if enable_syslog_ { LogEnableSyslog()} + if enable_debug_ { LogEnableDebuglog()} + Syslog_.Print("started") + defer Syslog_.Print("exiting") + zmqctx, cmd_chans, pub_chans := ZmqsInit(cmd_port_, pub_port_) defer cmd_chans.Close() defer pub_chans.Close() @@ -49,17 +52,6 @@ func main() { panic(err) } - if use_syslog_ { - var logerr error - Syslog_, logerr = syslog.NewLogger(syslog.LOG_INFO | syslog.LOG_LOCAL1, 0) - if logerr != nil { panic(logerr) } - Syslog_.Print("started") - defer Syslog_.Print("exiting") - } - - //~ serial_wr <- "f" - //~ firmware_version := <- serial_rd - //~ log.Print("Firmware version:", firmware_version) var next_incoming_serial_is_client_reply bool timeout_chan := make(chan bool) defer close(timeout_chan) @@ -93,15 +85,11 @@ func main() { cmd_chans.Out() <- [][]byte{[]byte("ERROR"), []byte("argument missing")} continue } - if Syslog_ == nil { - cmd_chans.Out() <- [][]byte{[]byte("ERROR"), []byte("syslog logging not enabled")} - continue - } Syslog_.Printf("Log: %s",incoming_request[1:]) cmd_chans.Out() <- [][]byte{[]byte("Ok")} continue } - if Syslog_ != nil { Syslog_.Printf("%s",incoming_request) } + Syslog_.Printf("%s",incoming_request) if err := HandleCommand(incoming_request, serial_wr, serial_rd); err != nil { out_msg := [][]byte{[]byte("ERROR"), []byte(err.Error())} cmd_chans.Out() <- out_msg diff --git a/go/door_daemon_zmq/serial_tty.go b/go/door_daemon_zmq/serial_tty.go index a5528d5..e609971 100644 --- a/go/door_daemon_zmq/serial_tty.go +++ b/go/door_daemon_zmq/serial_tty.go @@ -3,12 +3,10 @@ package main import ( - "fmt" "bufio" "bytes" "os" "svn.spreadspace.org/realraum/go.svn/termios" - "log" ) @@ -17,7 +15,7 @@ import ( func openTTY(name string) (*os.File, error) { file, err := os.OpenFile(name,os.O_RDWR, 0600) // For read access. if err != nil { - log.Println(err.Error()) + Syslog_.Println(err.Error()) return nil, err } termios.Ttyfd(file.Fd()) @@ -30,7 +28,7 @@ func serialWriter(in <- chan string, serial * os.File) { serial.WriteString(totty) serial.Sync() } - close(serial) + serial.Close() } func serialReader(out chan <- [][]byte, serial * os.File) { @@ -38,7 +36,7 @@ func serialReader(out chan <- [][]byte, serial * os.File) { linescanner.Split(bufio.ScanLines) for linescanner.Scan() { if err := linescanner.Err(); err != nil { - panic(fmt.Sprintf("Error in read from serial: %v\n",err.Error())) + panic(err.Error()) } text := bytes.Fields([]byte(linescanner.Text())) if len(text) == 0 { diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index d5b3e2f..a75582e 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -40,7 +40,7 @@ func init() { flag.StringVar(&r3eventssub_port_, "eventsubport", "tcp://wuzzler.realraum.at:4244", "zmq address to subscribe r3events") flag.StringVar(&brain_connect_addr_, "brainconnect", "tcp://wuzzler.realraum.at:4245", "address to ask about most recent stored events") flag.BoolVar(&enable_syslog_, "syslog", false, "enable logging to syslog") - flag.BoolVar(&enable_debug_, "debug", false, "enable debug logging") + flag.BoolVar(&enable_debug_, "debug", false, "enable debug output") flag.Parse() } -- 1.7.10.4