@@ -13,8 +13,10 @@ class LogstashHandler(DatagramHandler):
13
13
:param fqdn; Indicates whether to show fully qualified domain name or not (default False).
14
14
"""
15
15
16
- def __init__ (self , host , port = 5959 , message_type = 'logstash' , fqdn = False ):
16
+ def __init__ (self , host , port = 5959 , message_type = 'logstash' ,
17
+ message_path = 'logstash' , fqdn = False ):
17
18
self .message_type = message_type
19
+ self .message_path = message_path
18
20
self .fqdn = fqdn
19
21
DatagramHandler .__init__ (self , host , port )
20
22
@@ -36,7 +38,9 @@ def build_message(self, record):
36
38
'logger' : record .name ,
37
39
},
38
40
'@message' : record .getMessage (),
39
- '@source' : host ,
41
+ '@source' : self .format_source (host ),
42
+ '@source_host' : host ,
43
+ '@source_path' : self .message_path ,
40
44
'@tags' : [],
41
45
'@timestamp' : self .format_timestamp (record .created ),
42
46
'@type' : self .message_type ,
@@ -84,4 +88,7 @@ def format_exception(self, exc_info):
84
88
return '' .join (traceback .format_exception (* exc_info )) if exc_info else ''
85
89
86
90
def format_timestamp (self , time ):
87
- return datetime .utcfromtimestamp (time ).isoformat ()
91
+ return datetime .utcfromtimestamp (time ).isoformat ()
92
+
93
+ def format_source (self , host ):
94
+ return "%s://%s/%s" % (self .message_type , host , self .message_path )
0 commit comments