From 6f31e8ebe90661e8a2ccd80d4273afc9b8b2966f Mon Sep 17 00:00:00 2001 From: Mazz Mosley Date: Tue, 7 Jul 2015 12:40:16 +0100 Subject: [PATCH] Add support for log_opt When specifying a log_driver you want to specify some options for the logger as per the docker run --log-opt option. The logger options are key value pairs. Signed-off-by: Mazz Mosley --- compose/config.py | 1 + compose/service.py | 6 +++++- docs/yml.md | 8 ++++++++ tests/unit/service_test.py | 11 +++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/compose/config.py b/compose/config.py index 08be91662..2baf327b0 100644 --- a/compose/config.py +++ b/compose/config.py @@ -33,6 +33,7 @@ DOCKER_CONFIG_KEYS = [ 'memswap_limit', 'net', 'log_driver', + 'log_opt', 'pid', 'ports', 'privileged', diff --git a/compose/service.py b/compose/service.py index 6fec794fa..33cc9f618 100644 --- a/compose/service.py +++ b/compose/service.py @@ -40,6 +40,7 @@ DOCKER_START_KEYS = [ 'read_only', 'net', 'log_driver', + 'log_opt', 'pid', 'privileged', 'restart', @@ -583,7 +584,10 @@ class Service(object): privileged = options.get('privileged', False) cap_add = options.get('cap_add', None) cap_drop = options.get('cap_drop', None) - log_config = LogConfig(type=options.get('log_driver', 'json-file')) + log_config = LogConfig( + type=options.get('log_driver', 'json-file'), + config=options.get('log_opt', None) + ) pid = options.get('pid', None) security_opt = options.get('security_opt', None) diff --git a/docs/yml.md b/docs/yml.md index 4bab73b2b..ddf3e6cc6 100644 --- a/docs/yml.md +++ b/docs/yml.md @@ -248,6 +248,14 @@ The default value is json-file. log_driver: "syslog" log_driver: "none" +Specify logging options with `log_opt` for the logging driver, as with the ``--log-opt`` option for `docker run`. + +Logging options are key value pairs. An example of `syslog` options: + + log_driver: "syslog" + log_opt: + address: "tcp://192.168.0.42:123" + ### net Networking mode. Use the same values as the docker client `--net` parameter. diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py index d36937150..550a675ab 100644 --- a/tests/unit/service_test.py +++ b/tests/unit/service_test.py @@ -5,6 +5,7 @@ from .. import unittest import mock import docker +from docker.utils import LogConfig from compose.service import Service from compose.container import Container @@ -162,6 +163,16 @@ class ServiceTest(unittest.TestCase): self.assertEqual(opts['memswap_limit'], 2000000000) self.assertEqual(opts['mem_limit'], 1000000000) + def test_log_opt(self): + log_opt = {'address': 'tcp://192.168.0.42:123'} + service = Service(name='foo', image='foo', hostname='name', client=self.mock_client, log_driver='syslog', log_opt=log_opt) + self.mock_client.containers.return_value = [] + opts = service._get_container_create_options({'some': 'overrides'}, 1) + + self.assertIsInstance(opts['host_config']['LogConfig'], LogConfig) + self.assertEqual(opts['host_config']['LogConfig'].type, 'syslog') + self.assertEqual(opts['host_config']['LogConfig'].config, log_opt) + def test_split_domainname_fqdn(self): service = Service( 'foo',