Skip to content

Commit 5c17f33

Browse files
author
Vladimir Klochan
committed
Used LogRecord.pathname for source_path field.
1 parent ff6a7e5 commit 5c17f33

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
*.py[cod]
2+
MANIFEST
3+
.idea
24

35
# C extensions
46
*.so

logstash/handler.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ class LogstashHandler(DatagramHandler):
1313
:param fqdn; Indicates whether to show fully qualified domain name or not (default False).
1414
"""
1515

16-
def __init__(self, host, port=5959, message_type='logstash',
17-
message_path='logstash', fqdn=False):
16+
def __init__(self, host, port=5959, message_type='logstash', fqdn=False):
1817
self.message_type = message_type
19-
self.message_path = message_path
2018
self.fqdn = fqdn
2119
DatagramHandler.__init__(self, host, port)
2220

@@ -38,9 +36,9 @@ def build_message(self, record):
3836
'logger': record.name,
3937
},
4038
'@message': record.getMessage(),
41-
'@source': self.format_source(host),
39+
'@source': self.format_source(host, record.pathname),
4240
'@source_host': host,
43-
'@source_path': self.message_path,
41+
'@source_path': record.pathname,
4442
'@tags': [],
4543
'@timestamp': self.format_timestamp(record.created),
4644
'@type': self.message_type,
@@ -52,7 +50,6 @@ def build_message(self, record):
5250

5351
if add_debug_info:
5452
message_dict['@fields']['lineno'] = record.lineno
55-
message_dict['@fields']['pathname'] = record.pathname
5653
message_dict['@fields']['process'] = record.process
5754
message_dict['@fields']['threadName'] = record.threadName
5855
# funName was added in 2.5
@@ -90,5 +87,5 @@ def format_exception(self, exc_info):
9087
def format_timestamp(self, time):
9188
return datetime.utcfromtimestamp(time).isoformat()
9289

93-
def format_source(self, host):
94-
return "%s://%s/%s" % (self.message_type, host, self.message_path)
90+
def format_source(self, host, path):
91+
return "%s://%s/%s" % (self.message_type, host, path)

0 commit comments

Comments
 (0)