Пример #1
0
 def test_log_extra_value(self):
     gelf = GelfUdp(HOST, PORT)
     jsn = gelf.log(sys._getframe().f_code.co_name,
                    server='server',
                    test='test')
     self.assertEqual(jsn['server'], 'server')
     self.assertEqual(jsn['test'], 'test')
Пример #2
0
 def test_log_minimum(self):
     gelf = GelfUdp(HOST, PORT)
     jsn = gelf.log(sys._getframe().f_code.co_name)
     msg = jsn['short_message']
     self.assertEqual(msg, sys._getframe().f_code.co_name)
     self.assertEqual(jsn['host'], socket.gethostname())
     self.assertIsInstance(jsn['version'], string_types)
Пример #3
0
 def test_wrong_type_for_level(self):
     gelf = GelfUdp(HOST, PORT)
     with self.assertRaises(ValueError):
         jsn = gelf.log(sys._getframe().f_code.co_name,
                        level='not a number!')
Пример #4
0
 def test_out_of_range_level(self):
     gelf = GelfUdp(HOST, PORT)
     for level in [-1, 8]:
         with self.assertRaises(AssertionError):
             jsn = gelf.log(sys._getframe().f_code.co_name, level=level)
Пример #5
0
 def test_different_log_level(self):
     gelf = GelfUdp(HOST, PORT)
     for level in [0, 4, '0', '3', '7']:
         jsn = gelf.log(sys._getframe().f_code.co_name, level=level)
         self.assertEqual(jsn['level'], int(level))
Пример #6
0
 def test_default_log_level(self):
     gelf = GelfUdp(HOST, PORT)
     jsn = gelf.log(sys._getframe().f_code.co_name)
     self.assertEqual(jsn['level'], 1)
Пример #7
0
 def test_log_chunked_small_mtu(self):
     gelf = GelfUdp(HOST, PORT, mtu=50)
     data = random_string(gelf.mtu * 5)
     jsn = gelf.log(sys._getframe().f_code.co_name, data=data)
Пример #8
0
 def test_log_timestamp(self):
     gelf = GelfUdp(HOST, PORT)
     ts = time.time() - 120  # override timestamp 2 mintes in past
     jsn = gelf.log(sys._getframe().f_code.co_name, timestamp=ts)
     self.assertEqual(jsn['timestamp'], ts)
Пример #9
0
 def test_log_source_override(self):
     gelf = GelfUdp(HOST, PORT, source='source')
     jsn = gelf.log(sys._getframe().f_code.co_name, source='notsource')
     self.assertEqual(jsn['host'], 'notsource')
     jsn = gelf.log(sys._getframe().f_code.co_name, host='notsource')
     self.assertEqual(jsn['host'], 'notsource')
Пример #10
0
 def test_init(self):
     gelf = GelfUdp(HOST, PORT)
     self.assertEqual(gelf.server, HOST)
     self.assertIsInstance(gelf.port, int)
     self.assertEqual(gelf.source, socket.gethostname())
Пример #11
0
 def test_log_source(self):
     gelf = GelfUdp(HOST, PORT, source='source')
     jsn = gelf.log(sys._getframe().f_code.co_name)
     self.assertEquals(jsn['host'], 'source')