Allow log disable in account/container server
Logging can be disabled in the object server, but not in the account and container server though both sample configs already include that setting. This patch allows to disable logging for account and container server as well. Functionality is ensured by some additional tests. Closes-Bug: 1280954 Change-Id: Ia4e87911863089c3bea093d9f181ff29e9e963eb
This commit is contained in:
parent
4d4919ee7b
commit
b24a7dd4cb
@ -48,6 +48,7 @@ class AccountController(object):
|
|||||||
|
|
||||||
def __init__(self, conf, logger=None):
|
def __init__(self, conf, logger=None):
|
||||||
self.logger = logger or get_logger(conf, log_route='account-server')
|
self.logger = logger or get_logger(conf, log_route='account-server')
|
||||||
|
self.log_requests = config_true_value(conf.get('log_requests', 'true'))
|
||||||
self.root = conf.get('devices', '/srv/node')
|
self.root = conf.get('devices', '/srv/node')
|
||||||
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
|
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
|
||||||
replication_server = conf.get('replication_server', None)
|
replication_server = conf.get('replication_server', None)
|
||||||
@ -296,7 +297,8 @@ class AccountController(object):
|
|||||||
if res.headers.get('x-container-timestamp') is not None:
|
if res.headers.get('x-container-timestamp') is not None:
|
||||||
additional_info += 'x-container-timestamp: %s' % \
|
additional_info += 'x-container-timestamp: %s' % \
|
||||||
res.headers['x-container-timestamp']
|
res.headers['x-container-timestamp']
|
||||||
log_message = '%s - - [%s] "%s %s" %s %s "%s" "%s" "%s" %s "%s"' % (
|
if self.log_requests:
|
||||||
|
log_msg = '%s - - [%s] "%s %s" %s %s "%s" "%s" "%s" %s "%s"' % (
|
||||||
req.remote_addr,
|
req.remote_addr,
|
||||||
time.strftime('%d/%b/%Y:%H:%M:%S +0000', time.gmtime()),
|
time.strftime('%d/%b/%Y:%H:%M:%S +0000', time.gmtime()),
|
||||||
req.method, req.path,
|
req.method, req.path,
|
||||||
@ -306,9 +308,9 @@ class AccountController(object):
|
|||||||
trans_time,
|
trans_time,
|
||||||
additional_info)
|
additional_info)
|
||||||
if req.method.upper() == 'REPLICATE':
|
if req.method.upper() == 'REPLICATE':
|
||||||
self.logger.debug(log_message)
|
self.logger.debug(log_msg)
|
||||||
else:
|
else:
|
||||||
self.logger.info(log_message)
|
self.logger.info(log_msg)
|
||||||
return res(env, start_response)
|
return res(env, start_response)
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class ContainerController(object):
|
|||||||
|
|
||||||
def __init__(self, conf, logger=None):
|
def __init__(self, conf, logger=None):
|
||||||
self.logger = logger or get_logger(conf, log_route='container-server')
|
self.logger = logger or get_logger(conf, log_route='container-server')
|
||||||
|
self.log_requests = config_true_value(conf.get('log_requests', 'true'))
|
||||||
self.root = conf.get('devices', '/srv/node')
|
self.root = conf.get('devices', '/srv/node')
|
||||||
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
|
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
|
||||||
self.node_timeout = int(conf.get('node_timeout', 3))
|
self.node_timeout = int(conf.get('node_timeout', 3))
|
||||||
@ -501,6 +502,7 @@ class ContainerController(object):
|
|||||||
{'method': req.method, 'path': req.path})
|
{'method': req.method, 'path': req.path})
|
||||||
res = HTTPInternalServerError(body=traceback.format_exc())
|
res = HTTPInternalServerError(body=traceback.format_exc())
|
||||||
trans_time = '%.4f' % (time.time() - start_time)
|
trans_time = '%.4f' % (time.time() - start_time)
|
||||||
|
if self.log_requests:
|
||||||
log_message = '%s - - [%s] "%s %s" %s %s "%s" "%s" "%s" %s' % (
|
log_message = '%s - - [%s] "%s %s" %s %s "%s" "%s" "%s" %s' % (
|
||||||
req.remote_addr,
|
req.remote_addr,
|
||||||
time.strftime('%d/%b/%Y:%H:%M:%S +0000',
|
time.strftime('%d/%b/%Y:%H:%M:%S +0000',
|
||||||
|
@ -20,6 +20,7 @@ import unittest
|
|||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
from test.unit import FakeLogger
|
||||||
|
|
||||||
import simplejson
|
import simplejson
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
@ -1634,5 +1635,23 @@ class TestAccountController(unittest.TestCase):
|
|||||||
response = self.controller.__call__(env, start_response)
|
response = self.controller.__call__(env, start_response)
|
||||||
self.assertEqual(response, answer)
|
self.assertEqual(response, answer)
|
||||||
|
|
||||||
|
def test_GET_log_requests_true(self):
|
||||||
|
self.controller.logger = FakeLogger()
|
||||||
|
self.controller.log_requests = True
|
||||||
|
|
||||||
|
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'GET'})
|
||||||
|
resp = req.get_response(self.controller)
|
||||||
|
self.assertEqual(resp.status_int, 404)
|
||||||
|
self.assertTrue(self.controller.logger.log_dict['info'])
|
||||||
|
|
||||||
|
def test_GET_log_requests_false(self):
|
||||||
|
self.controller.logger = FakeLogger()
|
||||||
|
self.controller.log_requests = False
|
||||||
|
req = Request.blank('/sda1/p/a', environ={'REQUEST_METHOD': 'GET'})
|
||||||
|
resp = req.get_response(self.controller)
|
||||||
|
self.assertEqual(resp.status_int, 404)
|
||||||
|
self.assertFalse(self.controller.logger.log_dict['info'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -21,6 +21,7 @@ from contextlib import contextmanager
|
|||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
|
from test.unit import FakeLogger
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
|
||||||
from eventlet import spawn, Timeout, listen
|
from eventlet import spawn, Timeout, listen
|
||||||
@ -1851,6 +1852,23 @@ class TestContainerController(unittest.TestCase):
|
|||||||
response = self.controller.__call__(env, start_response)
|
response = self.controller.__call__(env, start_response)
|
||||||
self.assertEqual(response, answer)
|
self.assertEqual(response, answer)
|
||||||
|
|
||||||
|
def test_GET_log_requests_true(self):
|
||||||
|
self.controller.logger = FakeLogger()
|
||||||
|
self.controller.log_requests = True
|
||||||
|
|
||||||
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
||||||
|
resp = req.get_response(self.controller)
|
||||||
|
self.assertEqual(resp.status_int, 404)
|
||||||
|
self.assertTrue(self.controller.logger.log_dict['info'])
|
||||||
|
|
||||||
|
def test_GET_log_requests_false(self):
|
||||||
|
self.controller.logger = FakeLogger()
|
||||||
|
self.controller.log_requests = False
|
||||||
|
req = Request.blank('/sda1/p/a/c', environ={'REQUEST_METHOD': 'GET'})
|
||||||
|
resp = req.get_response(self.controller)
|
||||||
|
self.assertEqual(resp.status_int, 404)
|
||||||
|
self.assertFalse(self.controller.logger.log_dict['info'])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user