Skip to content

Error Handling of TCPLogstashHandler When Writing to Logstash #93

Description

@XuejiaoZhang

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions