Skip to content

Commit

Permalink
Adds a third example for the HTTP transport
Browse files Browse the repository at this point in the history
Signed-off-by: Jürgen Löhel <juergen.loehel@inlyse.com>
  • Loading branch information
jloehel committed Sep 27, 2020
1 parent 80c066e commit 0f4266c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions example3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-

import logging

from logstash_async.transport import HttpTransport
from logstash_async.handler import AsynchronousLogstashHandler

host = 'localhost'
port = 5959

logger = logging.getLogger("logstash_async.transport")
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
logging_format = "%(asctime)s.%(msecs)03d"
logging_format += " | %(levelname)-8s"
logging_format += " | %(name)s.%(module)s.%(funcName)s"
logging_format += " | %(message)s"
date_format = "%Y-%m-%d | %H:%M:%S"
formatter = logging.Formatter(logging_format, date_format)
handler.setFormatter(formatter)
logger.addHandler(handler)

test_logger = logging.getLogger("test")
test_logger.setLevel(logging.DEBUG)
transport = HttpTransport(
host,
port,
ssl_enable=False,
timeout=5.0,
username="logstash",
password="testing",
)
handler = AsynchronousLogstashHandler(
host,
port,
ssl_enable=False,
transport=transport,
database_path='logstash_test.db'
)
test_logger.addHandler(handler)

# These tests crash logstash if the heap space is not enough
for _ in range(11):
test_logger.critical('A' * 10 * 1024 * 1024)
test_logger.fatal("A" * 100 * 1024 * 1024)

for i in range(50):
test_logger.info("test %s", i)

test_logger.info("end")

0 comments on commit 0f4266c

Please sign in to comment.