Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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!')
Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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())
Ejemplo n.º 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')