Skip to content

Commit 7c7d5c6

Browse files
authored
Merge pull request #18 from SpainTrain/support-tags
feat(tags): Allow tags to be configured
2 parents cae0c03 + 6adc21e commit 7c7d5c6

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ The default level passed along with every log sent through this instance.
205205
By default the line has a maximum length of 16000 chars, this can be turned off with the value false.
206206

207207

208+
##### tags
209+
210+
* _Optional_
211+
* Type: `String[]`
212+
* Default: `[]`
213+
214+
List of tags used to dynamically group hosts. More information on tags is available at [How Do I Use Host Tags?](https://docs.logdna.com/docs/logdna-agent#section-how-do-i-use-host-tags-)
215+
216+
208217
### log(line, [options])
209218
---
210219
#### line

logdna/logdna.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def __init__(self, key, options={}):
2323
self.env = options['env'] if 'env' in options else ''
2424
self.setLevel(logging.DEBUG)
2525

26+
self.tags = []
27+
if 'tags' in options and isinstance(options['tags'], list):
28+
self.tags.extend(options['tags'])
2629
self.max_length = True
2730
if 'max_length' in options:
2831
self.max_length = options['max_length']
@@ -71,7 +74,17 @@ def flush(self):
7174
self.flusher = Timer(defaults['FLUSH_NOW'], self.flush)
7275
self.flusher.start()
7376
else:
74-
resp = requests.post(url=defaults['LOGDNA_URL'], json=data, auth=('user', self.key), params={ 'hostname': self.hostname, 'ip': self.ip, 'mac': self.mac if self.mac else None }, stream=True, timeout=defaults['MAX_REQUEST_TIMEOUT'])
77+
resp = requests.post(
78+
url=defaults['LOGDNA_URL'],
79+
json=data,
80+
auth=('user', self.key),
81+
params={
82+
'hostname': self.hostname,
83+
'ip': self.ip,
84+
'mac': self.mac if self.mac else None,
85+
'tags': self.tags if self.tags else None},
86+
stream=True,
87+
timeout=defaults['MAX_REQUEST_TIMEOUT'])
7588
self.buf = []
7689
self.bufByteLength = 0
7790
if self.flusher:

0 commit comments

Comments
 (0)