Skip to content

Commit

Permalink
initializing logging from the application since the rotation mechanis…
Browse files Browse the repository at this point in the history
…m from twistd seems to be designed to suck out of the box
  • Loading branch information
mriehl committed Mar 19, 2013
1 parent 35886f4 commit 9df9da4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main/python/yadtreceiver/__init__.py
Expand Up @@ -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

Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/main/python/yadtreceiver/yadtreceiver
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/unittest/python/yadtreceiver_tests.py
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9df9da4

Please sign in to comment.