Permalink
Browse files

Revert "removing call to startLogging because twistd already does it"…

… since the rotation mechanism sucks out of the box (needs write permission on the file to rotate, and the file is

created before dropping privileges..)

This reverts commit 08dd553.
  • Loading branch information...
1 parent 8dbbdc3 commit 35886f4f1ba8e5429b15cb434af96432591884f4 @mriehl mriehl committed Mar 19, 2013
Showing with 28 additions and 1 deletion.
  1. +5 −1 src/main/python/yadtreceiver/__init__.py
  2. +23 −0 src/unittest/python/yadtreceiver_tests.py
@@ -220,10 +220,14 @@ def set_configuration(self, configuration):
self.configuration = configuration
+ def initialize_twisted_logging(self):
+ log.startLogging(LogFile.fromFullPath(self.configuration['log_filename']))
+
def startService(self):
"""
- Establishes connection to broadcaster.
+ Initializes logging and establishes connection to broadcaster.
"""
+ self.initialize_twisted_logging()
log.msg('yadtreceiver version %s' % __version__)
self._client_watchdog()
self._refresh_connection(first_call=True)
@@ -22,6 +22,7 @@
from mock import Mock, call, patch
from twisted.mail.scripts.mailmail import Configuration
+from twisted.python.logfile import LogFile
from yadtreceiver import __version__, Receiver, ReceiverException
from yadtreceiver.events import Event
@@ -31,6 +32,21 @@ class YadtReceiverTests (unittest.TestCase):
def test_if_this_test_fails_maybe_you_have_yadtreceiver_installed_locally(self):
self.assertEqual('${version}', __version__)
+ @patch('yadtreceiver.LogFile')
+ @patch('yadtreceiver.log')
+ def test_should_call_start_logging_when_initializing_twisted_logging(self, mock_log, mock_log_file_class):
+ receiver = Receiver()
+ receiver.set_configuration({'log_filename': 'log/file.log',
+ 'targets': set(['devabc123']),
+ 'broadcaster_host': 'broadcaster_host',
+ 'broadcaster_port': 1234})
+ mock_log_file = Mock(LogFile)
+ mock_log_file_class.fromFullPath.return_value = mock_log_file
+
+ receiver.initialize_twisted_logging()
+
+ self.assertEquals(call(mock_log_file), mock_log.startLogging.call_args)
+
def test_should_set_configuration(self):
configuration = 'configuration'
receiver = Receiver()
@@ -113,6 +129,13 @@ def test_should_initialize_watchdog_and_start_connection_when_service_starts(sel
self.assertEquals(call(), mock_receiver._client_watchdog.call_args)
self.assertEquals(call(first_call=True), mock_receiver._refresh_connection.call_args)
+ def test_should_initialize_logging_when_service_starts(self):
+ mock_receiver = Mock(Receiver)
+
+ Receiver.startService(mock_receiver)
+
+ self.assertEquals(call(), mock_receiver.initialize_twisted_logging.call_args)
+
def test_should_subscribe_to_target_from_configuration_when_connected(self):
receiver = Receiver()
mock_broadcaster_client = Mock()

0 comments on commit 35886f4

Please sign in to comment.