Permalink
Browse files

initializing logging from the application since the rotation mechanis…

…m from twistd seems to be designed to suck out of the box
  • Loading branch information...
1 parent 35886f4 commit 9df9da4f8f7bed83543609c4b94427fbf8dc1915 @mriehl mriehl committed Mar 19, 2013
@@ -32,7 +32,7 @@
from twisted.application import service
from twisted.internet import reactor
from twisted.python import log
-from twisted.python.logfile import LogFile
+from twisted.python.logfile import DailyLogFile
from yadtbroadcastclient import WampBroadcaster
@@ -221,7 +221,8 @@ def set_configuration(self, configuration):
def initialize_twisted_logging(self):
- log.startLogging(LogFile.fromFullPath(self.configuration['log_filename']))
+ log_file = DailyLogFile.fromFullPath(self.configuration['log_filename'], maxRotatedFiles=30)
+ log.startLogging(log_file)
def startService(self):
"""
@@ -25,7 +25,7 @@ PID=$(get_pid)
case "${1:-}" in
start)
if [[ -z $PID ]]; then
- $TWISTD --pidfile=$PIDFILE --python=$TACFILE --logfile=$LOGFILE ${uid:+--uid=$uid} ${gid:+--gid=$gid}
+ $TWISTD --pidfile=$PIDFILE --python=$TACFILE ${uid:+--uid=$uid} ${gid:+--gid=$gid}
echo "$0 started, returning 0" && exit 0
else
echo "$0 already running (pid $PID), returning 0" && exit 0
@@ -22,7 +22,7 @@
from mock import Mock, call, patch
from twisted.mail.scripts.mailmail import Configuration
-from twisted.python.logfile import LogFile
+from twisted.python.logfile import DailyLogFile
from yadtreceiver import __version__, Receiver, ReceiverException
from yadtreceiver.events import Event
@@ -32,19 +32,20 @@ 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.DailyLogFile')
@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 = Mock(DailyLogFile)
mock_log_file_class.fromFullPath.return_value = mock_log_file
receiver.initialize_twisted_logging()
+ self.assertEqual(call('log/file.log', maxRotatedFiles=30), mock_log_file_class.fromFullPath.call_args)
self.assertEquals(call(mock_log_file), mock_log.startLogging.call_args)
def test_should_set_configuration(self):
@@ -118,7 +119,7 @@ def test_should_exit_when_no_target_configured(self, mock_exit, mock_log):
self.assertEquals(call(1), mock_exit.call_args)
- @patch('yadtreceiver.LogFile')
+ @patch('yadtreceiver.DailyLogFile')
@patch('yadtreceiver.log')
def test_should_initialize_watchdog_and_start_connection_when_service_starts(self, mock_log, mock_log_file):
mock_receiver = Mock(Receiver)

0 comments on commit 9df9da4

Please sign in to comment.