Clean up logger-calls - more semetrical through out the code
This commit is contained in:
parent
b77fc78dde
commit
3c7b11c149
10 changed files with 37 additions and 31 deletions
|
@ -148,7 +148,7 @@ class CoAP(object):
|
|||
:param message: the message to send
|
||||
"""
|
||||
host, port = message.destination
|
||||
logger.debug("send_datagram - " + str(message))
|
||||
logger.info("send_datagram - " + str(message))
|
||||
serializer = Serializer()
|
||||
raw_message = serializer.serialize(message)
|
||||
|
||||
|
@ -263,7 +263,7 @@ class CoAP(object):
|
|||
message = serializer.deserialize(datagram, source)
|
||||
|
||||
if isinstance(message, Response):
|
||||
logger.debug("receive_datagram - " + str(message))
|
||||
logger.info("receive_datagram - " + str(message))
|
||||
transaction, send_ack = self._messageLayer.receive_response(message)
|
||||
if transaction is None: # pragma: no cover
|
||||
continue
|
||||
|
|
|
@ -139,7 +139,7 @@ class CoAP(object):
|
|||
except socket.timeout:
|
||||
continue
|
||||
try:
|
||||
#Start a new thread not to block other requests
|
||||
# Start a new thread not to block other requests
|
||||
args = ((data, client_address), )
|
||||
t = threading.Thread(target=self.receive_datagram, args=args)
|
||||
t.daemon = True
|
||||
|
@ -188,20 +188,20 @@ class CoAP(object):
|
|||
rst.code = message
|
||||
self.send_datagram(rst)
|
||||
return
|
||||
logger.debug("receive_datagram - " + str(message))
|
||||
logger.info("receive_datagram - " + str(message))
|
||||
if isinstance(message, Request):
|
||||
|
||||
transaction = self._messageLayer.receive_request(message)
|
||||
|
||||
if transaction.request.duplicated and transaction.completed:
|
||||
logger.debug("message duplicated,transaction completed")
|
||||
logger.debug("message duplicated, transaction completed")
|
||||
transaction = self._observeLayer.send_response(transaction)
|
||||
transaction = self._blockLayer.send_response(transaction)
|
||||
transaction = self._messageLayer.send_response(transaction)
|
||||
self.send_datagram(transaction.response)
|
||||
return
|
||||
elif transaction.request.duplicated and not transaction.completed:
|
||||
logger.debug("message duplicated,transaction NOT completed")
|
||||
logger.debug("message duplicated, transaction NOT completed")
|
||||
self._send_ack(transaction)
|
||||
return
|
||||
|
||||
|
@ -268,7 +268,7 @@ class CoAP(object):
|
|||
"""
|
||||
if not self.stopped.isSet():
|
||||
host, port = message.destination
|
||||
logger.debug("send_datagram - " + str(message))
|
||||
logger.info("send_datagram - " + str(message))
|
||||
serializer = Serializer()
|
||||
|
||||
message = serializer.serialize(message)
|
||||
|
|
|
@ -175,7 +175,7 @@ class HCProxyHandler(BaseHTTPRequestHandler):
|
|||
logger.debug(payload)
|
||||
coap_response = self.client.put(self.coap_uri.path, payload)
|
||||
self.client.stop()
|
||||
logger.debug("Server response: %s", coap_response.pretty_print())
|
||||
logger.info("Server response: %s", coap_response.pretty_print())
|
||||
self.set_http_response(coap_response)
|
||||
|
||||
def do_DELETE(self):
|
||||
|
@ -185,7 +185,7 @@ class HCProxyHandler(BaseHTTPRequestHandler):
|
|||
self.do_initial_operations()
|
||||
coap_response = self.client.delete(self.coap_uri.path)
|
||||
self.client.stop()
|
||||
logger.debug("Server response: %s", coap_response.pretty_print())
|
||||
logger.info("Server response: %s", coap_response.pretty_print())
|
||||
self.set_http_response(coap_response)
|
||||
|
||||
def do_CONNECT(self):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import copy
|
||||
import logging
|
||||
from coapthon.messages.request import Request
|
||||
from coapclient import HelperClient
|
||||
from coapthon.messages.response import Response
|
||||
|
@ -8,6 +9,8 @@ from coapthon.utils import parse_uri
|
|||
|
||||
__author__ = 'Giacomo Tanganelli'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ForwardLayer(object):
|
||||
"""
|
||||
|
@ -146,8 +149,10 @@ class ForwardLayer(object):
|
|||
request.destination = transaction.resource.remote_server
|
||||
request.payload = transaction.request.payload
|
||||
request.code = transaction.request.code
|
||||
logger.info("forward_request - " + str(request))
|
||||
response = client.send_request(request)
|
||||
client.stop()
|
||||
logger.info("forward_response - " + str(response))
|
||||
transaction.response.payload = response.payload
|
||||
transaction.response.code = response.code
|
||||
transaction.response.options = response.options
|
||||
|
|
|
@ -72,7 +72,7 @@ class MessageLayer(object):
|
|||
:rtype : Transaction
|
||||
:return: the edited transaction
|
||||
"""
|
||||
logger.debug("receive_request - " + str(request))
|
||||
logger.info("receive_request - " + str(request))
|
||||
try:
|
||||
host, port = request.source
|
||||
except AttributeError:
|
||||
|
@ -101,7 +101,7 @@ class MessageLayer(object):
|
|||
:rtype : Transaction
|
||||
:return: the transaction to which the response belongs to
|
||||
"""
|
||||
logger.debug("receive_response - " + str(response))
|
||||
logger.info("receive_response - " + str(response))
|
||||
try:
|
||||
host, port = response.source
|
||||
except AttributeError:
|
||||
|
@ -148,7 +148,7 @@ class MessageLayer(object):
|
|||
:rtype : Transaction
|
||||
:return: the transaction to which the message belongs to
|
||||
"""
|
||||
logger.debug("receive_empty - " + str(message))
|
||||
logger.info("receive_empty - " + str(message))
|
||||
try:
|
||||
host, port = message.source
|
||||
except AttributeError:
|
||||
|
@ -201,7 +201,7 @@ class MessageLayer(object):
|
|||
:rtype : Transaction
|
||||
:return: the created transaction
|
||||
"""
|
||||
logger.debug("send_request - " + str(request))
|
||||
logger.info("send_request - " + str(request))
|
||||
assert isinstance(request, Request)
|
||||
try:
|
||||
host, port = request.destination
|
||||
|
@ -233,7 +233,7 @@ class MessageLayer(object):
|
|||
:rtype : Transaction
|
||||
:return: the edited transaction
|
||||
"""
|
||||
logger.debug("send_response - " + str(transaction.response))
|
||||
logger.info("send_response - " + str(transaction.response))
|
||||
if transaction.response.type is None:
|
||||
if transaction.request.type == defines.Types["CON"] and not transaction.request.acknowledged:
|
||||
transaction.response.type = defines.Types["ACK"]
|
||||
|
@ -268,7 +268,7 @@ class MessageLayer(object):
|
|||
:type message: Message
|
||||
:param message: the ACK or RST message to send
|
||||
"""
|
||||
logger.debug("send_empty - " + str(message))
|
||||
logger.info("send_empty - " + str(message))
|
||||
if transaction is None:
|
||||
try:
|
||||
host, port = message.destination
|
||||
|
|
|
@ -188,7 +188,7 @@ class ObserveLayer(object):
|
|||
|
||||
:param message: the message
|
||||
"""
|
||||
logger.debug("Remove Subcriber")
|
||||
logger.info("Remove Subcriber")
|
||||
host, port = message.destination
|
||||
key_token = hash(str(host) + str(port) + str(message.token))
|
||||
try:
|
||||
|
|
|
@ -695,6 +695,9 @@ class Message(object):
|
|||
.format(source=self._source, destination=self._destination, type=inv_types[self._type], mid=self._mid,
|
||||
code=defines.Codes.LIST[self._code].name, token=self._token)
|
||||
for opt in self._options:
|
||||
if 'Block' in opt.name:
|
||||
msg += "{name}: {value}, ".format(name=opt.name, value=parse_blockwise(opt.value))
|
||||
else:
|
||||
msg += "{name}: {value}, ".format(name=opt.name, value=opt.value)
|
||||
msg += "]"
|
||||
if self.payload is not None:
|
||||
|
|
|
@ -273,7 +273,8 @@ class CoAP(object):
|
|||
rst.code = message
|
||||
self.send_datagram(rst)
|
||||
return
|
||||
logger.debug("receive_datagram - " + str(message))
|
||||
|
||||
logger.info("receive_datagram - " + str(message))
|
||||
if isinstance(message, Request):
|
||||
|
||||
transaction = self._messageLayer.receive_request(message)
|
||||
|
@ -319,6 +320,7 @@ class CoAP(object):
|
|||
transaction = self._blockLayer.send_response(transaction)
|
||||
|
||||
transaction = self._cacheLayer.send_response(transaction)
|
||||
|
||||
else:
|
||||
transaction = self._forwardLayer.receive_request_reverse(transaction)
|
||||
|
||||
|
@ -353,7 +355,7 @@ class CoAP(object):
|
|||
"""
|
||||
if not self.stopped.isSet():
|
||||
host, port = message.destination
|
||||
logger.debug("send_datagram - " + str(message))
|
||||
logger.info("send_datagram - " + str(message))
|
||||
serializer = Serializer()
|
||||
message = serializer.serialize(message)
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ class Serializer(object):
|
|||
# the first 4 bits of the byte represent the option delta
|
||||
# delta = self._reader.read(4).uint
|
||||
num, option_length, pos = Serializer.read_option_value_len_from_byte(next_byte, pos, values)
|
||||
logger.debug("option value (delta): %d len: %d", num, option_length)
|
||||
current_option += num
|
||||
# read option
|
||||
try:
|
||||
|
@ -81,8 +82,7 @@ class Serializer(object):
|
|||
else:
|
||||
# If the non-critical option is unknown
|
||||
# (vendor-specific, proprietary) - just skip it
|
||||
#log.err("unrecognized option %d" % current_option)
|
||||
pass
|
||||
logger.warning("unrecognized option %d", current_option)
|
||||
else:
|
||||
if option_length == 0:
|
||||
value = None
|
||||
|
@ -313,6 +313,7 @@ class Serializer(object):
|
|||
length = struct.unpack("!B", values[pos].to_bytes(1, "big"))[0] + 13
|
||||
pos += 1
|
||||
elif l_nibble == 14:
|
||||
s = struct.Struct("!H")
|
||||
length = s.unpack_from(values[pos:].to_bytes(2, "big"))[0] + 269
|
||||
pos += 2
|
||||
else:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import logging.config
|
||||
import os
|
||||
import logging
|
||||
import random
|
||||
import socket
|
||||
import struct
|
||||
|
@ -17,17 +16,13 @@ from coapthon.messages.request import Request
|
|||
from coapthon.messages.response import Response
|
||||
from coapthon.resources.resource import Resource
|
||||
from coapthon.serializer import Serializer
|
||||
from coapthon.utils import Tree, create_logging
|
||||
from coapthon.utils import Tree
|
||||
|
||||
|
||||
__author__ = 'Giacomo Tanganelli'
|
||||
|
||||
|
||||
if not os.path.isfile("logging.conf"):
|
||||
create_logging()
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.config.fileConfig("logging.conf", disable_existing_loggers=False)
|
||||
|
||||
|
||||
class CoAP(object):
|
||||
|
@ -155,7 +150,7 @@ class CoAP(object):
|
|||
self.send_datagram(rst)
|
||||
continue
|
||||
|
||||
logger.debug("receive_datagram - " + str(message))
|
||||
logger.info("receive_datagram - " + str(message))
|
||||
if isinstance(message, Request):
|
||||
transaction = self._messageLayer.receive_request(message)
|
||||
if transaction.request.duplicated and transaction.completed:
|
||||
|
@ -247,7 +242,7 @@ class CoAP(object):
|
|||
"""
|
||||
if not self.stopped.isSet():
|
||||
host, port = message.destination
|
||||
logger.debug("send_datagram - " + str(message))
|
||||
logger.info("send_datagram - " + str(message))
|
||||
serializer = Serializer()
|
||||
message = serializer.serialize(message)
|
||||
self._socket.sendto(message, (host, port))
|
||||
|
|
Loading…
Reference in a new issue