mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-01 04:38:12 +00:00
Fix logging issues with the controller
This commit is contained in:
parent
4d77b2918e
commit
0532b4de8a
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class ControllerError(Exception):
|
class ControllerError(Exception):
|
||||||
|
|
||||||
def __init__(self, message):
|
def __init__(self, message):
|
||||||
super().__init__(message)
|
super().__init__(message)
|
||||||
self._message = message
|
self._message = message
|
||||||
@ -26,5 +27,3 @@ class ControllerError(Exception):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
from ..controller.controller_error import ControllerError
|
from ..controller.controller_error import ControllerError
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
|
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ServerError(ControllerError):
|
class ServerError(ControllerError):
|
||||||
pass
|
pass
|
||||||
@ -30,6 +33,7 @@ class Server:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, server_id, protocol="http", host="localhost", port=8000, user=None, password=None):
|
def __init__(self, server_id, protocol="http", host="localhost", port=8000, user=None, password=None):
|
||||||
|
log.info("Create server %s", server_id)
|
||||||
self._id = server_id
|
self._id = server_id
|
||||||
self._protocol = protocol
|
self._protocol = protocol
|
||||||
self._host = host
|
self._host = host
|
||||||
@ -69,5 +73,3 @@ class Server:
|
|||||||
"connected": self._connected,
|
"connected": self._connected,
|
||||||
"version": self._version
|
"version": self._version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import jsonschema
|
import jsonschema
|
||||||
|
import asyncio
|
||||||
import aiohttp.web
|
import aiohttp.web
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
@ -32,7 +33,6 @@ renderer = jinja2.Environment(loader=jinja2.FileSystemLoader(get_resource('templ
|
|||||||
class Response(aiohttp.web.Response):
|
class Response(aiohttp.web.Response):
|
||||||
|
|
||||||
def __init__(self, request=None, route=None, output_schema=None, headers={}, **kwargs):
|
def __init__(self, request=None, route=None, output_schema=None, headers={}, **kwargs):
|
||||||
|
|
||||||
self._route = route
|
self._route = route
|
||||||
self._output_schema = output_schema
|
self._output_schema = output_schema
|
||||||
self._request = request
|
self._request = request
|
||||||
@ -41,7 +41,8 @@ class Response(aiohttp.web.Response):
|
|||||||
headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__)
|
headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__)
|
||||||
super().__init__(headers=headers, **kwargs)
|
super().__init__(headers=headers, **kwargs)
|
||||||
|
|
||||||
def start(self, request):
|
@asyncio.coroutine
|
||||||
|
def prepare(self, request):
|
||||||
if log.getEffectiveLevel() == logging.DEBUG:
|
if log.getEffectiveLevel() == logging.DEBUG:
|
||||||
log.info("%s %s", request.method, request.path_qs)
|
log.info("%s %s", request.method, request.path_qs)
|
||||||
log.debug("%s", dict(request.headers))
|
log.debug("%s", dict(request.headers))
|
||||||
@ -51,7 +52,7 @@ class Response(aiohttp.web.Response):
|
|||||||
log.debug(dict(self.headers))
|
log.debug(dict(self.headers))
|
||||||
if hasattr(self, 'body') and self.body is not None and self.headers["CONTENT-TYPE"] == "application/json":
|
if hasattr(self, 'body') and self.body is not None and self.headers["CONTENT-TYPE"] == "application/json":
|
||||||
log.debug(json.loads(self.body.decode('utf-8')))
|
log.debug(json.loads(self.body.decode('utf-8')))
|
||||||
return super().start(request)
|
return (yield from super().prepare(request))
|
||||||
|
|
||||||
def html(self, answer):
|
def html(self, answer):
|
||||||
"""
|
"""
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
jsonschema>=2.4.0
|
jsonschema>=2.4.0
|
||||||
aiohttp==0.19.0
|
aiohttp==0.21.2
|
||||||
Jinja2>=2.7.3
|
Jinja2>=2.7.3
|
||||||
raven>=5.2.0
|
raven>=5.2.0
|
||||||
psutil>=3.0.0
|
psutil>=3.0.0
|
||||||
|
@ -44,6 +44,7 @@ def test_server_local(server):
|
|||||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||||
s = Server("test")
|
s = Server("test")
|
||||||
|
|
||||||
|
|
||||||
def test_json(server):
|
def test_json(server):
|
||||||
assert server.__json__() == {
|
assert server.__json__() == {
|
||||||
"server_id": "my_server_id",
|
"server_id": "my_server_id",
|
||||||
@ -54,4 +55,3 @@ def test_json(server):
|
|||||||
"connected": False,
|
"connected": False,
|
||||||
"version": None
|
"version": None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user