Merge pull request #1665 from mnowster/1648-support-log-opt

1648 support log opt
This commit is contained in:
Aanand Prasad 2015-07-07 17:08:04 +01:00
commit 8b033d3946
4 changed files with 26 additions and 2 deletions

View File

@ -24,7 +24,6 @@ DOCKER_CONFIG_KEYS = [
'env_file', 'env_file',
'environment', 'environment',
'extra_hosts', 'extra_hosts',
'read_only',
'hostname', 'hostname',
'image', 'image',
'labels', 'labels',
@ -34,9 +33,11 @@ DOCKER_CONFIG_KEYS = [
'memswap_limit', 'memswap_limit',
'net', 'net',
'log_driver', 'log_driver',
'log_opt',
'pid', 'pid',
'ports', 'ports',
'privileged', 'privileged',
'read_only',
'restart', 'restart',
'security_opt', 'security_opt',
'stdin_open', 'stdin_open',

View File

@ -40,6 +40,7 @@ DOCKER_START_KEYS = [
'read_only', 'read_only',
'net', 'net',
'log_driver', 'log_driver',
'log_opt',
'pid', 'pid',
'privileged', 'privileged',
'restart', 'restart',
@ -600,7 +601,10 @@ class Service(object):
privileged = options.get('privileged', False) privileged = options.get('privileged', False)
cap_add = options.get('cap_add', None) cap_add = options.get('cap_add', None)
cap_drop = options.get('cap_drop', 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) pid = options.get('pid', None)
security_opt = options.get('security_opt', None) security_opt = options.get('security_opt', None)

View File

@ -248,6 +248,14 @@ The default value is json-file.
log_driver: "syslog" log_driver: "syslog"
log_driver: "none" 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 ### net
Networking mode. Use the same values as the docker client `--net` parameter. Networking mode. Use the same values as the docker client `--net` parameter.

View File

@ -5,6 +5,7 @@ from .. import unittest
import mock import mock
import docker import docker
from docker.utils import LogConfig
from compose.service import Service from compose.service import Service
from compose.container import Container from compose.container import Container
@ -163,6 +164,16 @@ class ServiceTest(unittest.TestCase):
self.assertEqual(opts['memswap_limit'], 2000000000) self.assertEqual(opts['memswap_limit'], 2000000000)
self.assertEqual(opts['mem_limit'], 1000000000) 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): def test_split_domainname_fqdn(self):
service = Service( service = Service(
'foo', 'foo',