Skip to content

Error Handling of TCPLogstashHandler When Writing to Logstash #93

Open

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.

Activity

  1. changed the title [-]Error Handling of writing to Logstash[/-] [+]Error Handling of TCPLogstashHandler writing to Logstash[/+] on Dec 27, 2020
  2. XuejiaoZhang commented on Dec 27, 2020

    @XuejiaoZhang
    Author

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

  3. changed the title [-]Error Handling of TCPLogstashHandler writing to Logstash[/-] [+]Error Handling of TCPLogstashHandler When Writing to Logstash[/+] on Dec 28, 2020
  4. jehos commented on Feb 9, 2021

    @jehos

    ++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.

  5. kevinn-1 commented on Sep 28, 2022

    @kevinn-1

    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

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