示例#1
0
 def __call__(self, options):
     journal = Journal()
     journal.open_with_path(options.path)
     journal.begin_context(options.title or 'Error')
     try:
         journal.write_message(options.message,
                               **self.get_metadata(options))
     finally:
         journal.end_context(relation='ERROR')
         journal.terminate()
示例#2
0
  def test_iterator(self):
    journal = Journal()
    path = os.path.join(self.temp_dir, 'test_iterator.journal')
    expect = []

    journal.open_with_path(path, TestString='TestValue', TestNum=123)
    expect.append({'_type': 'JournalMessage',
                   '_value': 'Starting journal.',
                   'TestString': 'TestValue',
                   'TestNum': 123})

    journal.write_message('Initial Message')
    expect.append({'_type': 'JournalMessage', '_value': 'Initial Message'})
                   
    journal.begin_context('OUTER', TestProperty='BeginOuter')
    expect.append({'_type': 'JournalContextControl',
                   'control': 'BEGIN',
                   '_title': 'OUTER',
                   'TestProperty': 'BeginOuter'})

    journal.write_message('Context Message', format='pre')
    expect.append({'_type': 'JournalMessage', '_value': 'Context Message',
                   'format': 'pre'})
    
    journal.end_context(TestProperty='END OUTER')
    expect.append({'_type': 'JournalContextControl',
                   'control': 'END',
                   'TestProperty': 'END OUTER'})

    journal.terminate(EndProperty='xyz')
    expect.append({'_type': 'JournalMessage',
                   '_value': 'Finished journal.',
                   'EndProperty': 'xyz'})

    # We're going to pop off expect, so reverse it
    # so that we can check in order.
    expect.reverse()
    navigator = StreamJournalNavigator.new_from_path(path)
    for record in navigator:
        del(record['_thread'])
        del(record['_timestamp'])
        self.assertEquals(record, expect.pop())
    self.assertEquals([], expect)