Skip to content

Commit

Permalink
use proper log-handler, log directly to syslog
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed Apr 19, 2013
1 parent a383a48 commit 17056c6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ You can set `weather` to a json-file. This will be read in like the status-file
Running
-------

- Run `systemctl start pymultimonaprs` or just `pymultimonaprs` for testing
- Run `systemctl start pymultimonaprs` or just `pymultimonaprs -v` for testing
19 changes: 19 additions & 0 deletions bin/pymultimonaprs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import json
import threading
from time import sleep
import sys
import logging
import logging.handlers
import argparse

from pymultimonaprs import multimon
from pymultimonaprs import beacon
Expand All @@ -11,6 +15,21 @@ from pymultimonaprs.frame import APRSFrame, InvalidFrame

config = json.load(open('/etc/pymultimonaprs.json'))

parser = argparse.ArgumentParser(description='HF2APRS-IG Gateway.')
parser.add_argument('--syslog', action='store_true', help='Log to syslog')
parser.add_argument('-v', '--verbose', action='store_true', help='Log all traffic - including beacon')
args = parser.parse_args()

logger = logging.getLogger('pymultimonaprs')
loglevel = logging.DEBUG if args.verbose else logging.INFO
logger.setLevel(loglevel)
if args.syslog:
loghandler = logging.handlers.SysLogHandler(address = '/dev/log')
else:
loghandler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('[%(asctime)s] %(levelname)+8s: %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
loghandler.setFormatter(formatter)
logger.addHandler(loghandler)

def mmcb(ui_frame):
try:
Expand Down
2 changes: 1 addition & 1 deletion pymultimonaprs.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=PyMultimonAPRS
After=network.target

[Service]
ExecStart=/usr/bin/pymultimonaprs
ExecStart=/usr/bin/pymultimonaprs --syslog

[Install]
WantedBy=multi-user.target
18 changes: 10 additions & 8 deletions pymultimonaprs/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import Queue
import pkg_resources
import sys
import logging

class IGate:
def __init__(self, callsign, passcode, gateway):
self.log = logging.getLogger('pymultimonaprs')
self.server, self.port = gateway.split(':')
self.port = int(self.port)
self.callsign = callsign
Expand All @@ -23,12 +25,12 @@ def _connect(self):
# Connect
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ip = socket.gethostbyname(self.server)
print >> sys.stderr, "connecting... %s:%i" % (ip, self.port)
self.log.info("connecting... %s:%i" % (ip, self.port))
self.socket.connect((ip, self.port))
print >> sys.stderr, "connected"
self.log.info("connected")

server_hello = self.socket.recv(1024)
print >> sys.stderr, server_hello.strip(" \r\n")
self.log.info(server_hello.strip(" \r\n"))

# Try to get my version
try:
Expand All @@ -37,11 +39,11 @@ def _connect(self):
version = 'GIT'

# Login
print >> sys.stderr, "LOGIN: %s (PyMultimonAPRS %s)" % (self.callsign, version)
self.log.info("login %s (PyMultimonAPRS %s)" % (self.callsign, version))
self.socket.send("user %s pass %s vers PyMultimonAPRS %s filter r/38/-171/1\r\n" % (self.callsign, self.passcode, version))

server_return = self.socket.recv(1024)
print >> sys.stderr, server_return.strip(" \r\n")
self.log.info(server_return.strip(" \r\n"))

self.socket.setblocking(0)

Expand All @@ -55,14 +57,14 @@ def _socket_worker(self):
while True:
try:
tnc2_frame = self._sending_queue.get(True, 1)
print "sending: %s" % tnc2_frame
self.log.debug("sending: %s" % tnc2_frame)
self.socket.send("%s\r\n" % tnc2_frame)
except Queue.Empty:
pass
except socket.error, e:
if e.errno == 32:
# socket disconnected
print >> sys.stderr, "socket dead"
self.log.warn("socket dead")
self._connect()
# read from socket to prevent buffer fillup
try:
Expand All @@ -71,4 +73,4 @@ def _socket_worker(self):
if e.errno == 11:
# buffer empty
pass
print >> sys.stderr, "thread exit"
self.log.info("thread exit")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='pymultimonaprs',
version='0.7.2',
version='0.8.0',
license='GPL',
description='HF2APRS-IG Gateway',
author='Dominik Heidler',
Expand Down

0 comments on commit 17056c6

Please sign in to comment.