@@ -607,6 +607,44 @@ def test_stdout_prepend_timestamp(self):
607
607
dispatcher .childlog .close ()
608
608
dispatcher .close ()
609
609
610
+ def test_stdout_prepend_timestamp_format (self ):
611
+ import time
612
+ from supervisor import loggers
613
+ from supervisor .loggers import getLogger
614
+
615
+ options = DummyOptions ()
616
+ options .getLogger = getLogger # actually use real logger
617
+ options .loglevel = loggers .LevelsByName .TRAC
618
+
619
+ logfile = '/tmp/foo'
620
+ message = "testing prepand"
621
+ config = DummyPConfig (options , 'process1' , '/bin/process1' ,
622
+ stdout_logfile = logfile , stdout_prepend_timestamp = True ,
623
+ stdout_prepend_timestamp_format = "%H:%M:%S" )
624
+ process = DummyProcess (config )
625
+
626
+ dispatcher = self ._makeOne (process )
627
+ dispatcher .removelogs ()
628
+ dispatcher .output_buffer = message
629
+ dispatcher .record_output ()
630
+
631
+ # flush out the log into log files
632
+ [x .flush () for x in dispatcher .childlog .handlers ]
633
+
634
+ # logger will prefix the stdout log with the timestamp down to milliseconds
635
+ # but not feasible to test to that resolution
636
+ timestamp_prefix = time .strftime ("%H:%M:%S" )
637
+
638
+ with open (logfile , 'rb' ) as f :
639
+ content = f .read ()
640
+ # check if the timestamp is prepended to the log
641
+ self .assertEqual (timestamp_prefix .encode (), content [0 :len (timestamp_prefix )])
642
+ # check if the message is at the end of the log line
643
+ self .assertEqual (message .encode (), content [- len (message ):])
644
+
645
+ dispatcher .childlog .close ()
646
+ dispatcher .close ()
647
+
610
648
def test_stderr_prepend_timestamp (self ):
611
649
import time
612
650
from supervisor import loggers
@@ -644,6 +682,47 @@ def test_stderr_prepend_timestamp(self):
644
682
dispatcher .childlog .close ()
645
683
dispatcher .close ()
646
684
685
+ def test_stderr_prepend_timestamp_format (self ):
686
+ import time
687
+ from supervisor import loggers
688
+ from supervisor .loggers import getLogger
689
+
690
+ options = DummyOptions ()
691
+ options .getLogger = getLogger # actually use real logger
692
+ options .loglevel = loggers .LevelsByName .TRAC
693
+
694
+ logfile = '/tmp/foo'
695
+ message = "testing prepand"
696
+ config = DummyPConfig (options , 'process1' , '/bin/process1' ,
697
+ stderr_logfile = logfile , stderr_prepend_timestamp = True ,
698
+ stderr_prepend_timestamp_format = "%H:%M:%S" )
699
+ process = DummyProcess (config )
700
+
701
+ dispatcher = self ._makeOne (process , channel = 'stderr' )
702
+ dispatcher .output_buffer = message
703
+ dispatcher .removelogs ()
704
+ dispatcher .record_output ()
705
+
706
+ # flush out the log into log files
707
+ [x .flush () for x in dispatcher .childlog .handlers ]
708
+
709
+ # logger will prefix the stdout log with the timestamp down to milliseconds
710
+ # but not feasible to test to that resolution
711
+ timestamp_prefix = time .strftime ("%H:%M:%S" )
712
+
713
+ with open (logfile , 'rb' ) as f :
714
+ content = f .read ()
715
+ # check if the timestamp is prepended to the log
716
+ self .assertEqual (timestamp_prefix .encode (), content [0 :len (timestamp_prefix )])
717
+ # check if the message is at the end of the log line
718
+ self .assertEqual (message .encode (), content [- len (message ):])
719
+
720
+ dispatcher .childlog .close ()
721
+ dispatcher .close ()
722
+
723
+
724
+
725
+
647
726
class PInputDispatcherTests (unittest .TestCase ):
648
727
def _getTargetClass (self ):
649
728
from supervisor .dispatchers import PInputDispatcher
0 commit comments