Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling of TCPLogstashHandler When Writing to Logstash #93

Open
XuejiaoZhang opened this issue Dec 27, 2020 · 3 comments
Open

Error Handling of TCPLogstashHandler When Writing to Logstash #93

XuejiaoZhang opened this issue Dec 27, 2020 · 3 comments

Comments

@XuejiaoZhang
Copy link

XuejiaoZhang commented Dec 27, 2020

I added "try... except..." to example1.py of this repo as following:

import logging
import logstash
import sys

host = 'localhost'

try:
	test_logger = logging.getLogger('python-logstash-logger')
	test_logger.setLevel(logging.INFO)
	# test_logger.addHandler(logstash.LogstashHandler(host, 5959, version=1))
	test_logger.addHandler(logstash.TCPLogstashHandler(host, 5959, version=1))

	test_logger.error('python-logstash: test logstash error message.')
	test_logger.info('python-logstash: test logstash info message.')
	test_logger.warning('python-logstash: test logstash warning message.')

	# add extra field to logstash message
	extra = {
	    'test_string': 'python version: ' + repr(sys.version_info),
	    'test_boolean': True,
	    'test_dict': {'a': 1, 'b': 'c'},
	    'test_float': 1.23,
	    'test_integer': 123,
	    'test_list': [1, 2, '3'],
	}
	test_logger.info('python-logstash: test extra fields', extra=extra)

	print('Succeed to save event.')


except Exception as e:
	print('Failed to save event: ',e)

Even though no Logstash on my localhost, it will say "Succeed to save event", I am wondering how to add error handling of writing to Logstash with TCPLogstashHandler. Thanks.

@XuejiaoZhang XuejiaoZhang changed the title Error Handling of writing to Logstash Error Handling of TCPLogstashHandler writing to Logstash Dec 27, 2020
@XuejiaoZhang
Copy link
Author

@wizardion Would you please give us some hints on this? Thanks in advance!

@XuejiaoZhang XuejiaoZhang changed the title Error Handling of TCPLogstashHandler writing to Logstash Error Handling of TCPLogstashHandler When Writing to Logstash Dec 28, 2020
@jehos
Copy link

jehos commented Feb 9, 2021

++1

@vklochan

in my case, i wrote wrong address for logstash, but i didn't notice any sign of error. (eventually i found my mistake)
but still need some error messages if not correctly working everything.

@kevinn-1
Copy link

This one is really important - we need to check whether or not the event was successfully received by Logstash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants