Skip to main content

Easy Logstash

Easy Logstash is a python package that allows you to use logstash logging in your applications in very simple manner.

Because of using Python logstash async on the background, you can read more about the python logstash async at the link above.

Installation

Just pip install easy-logstash

Usage

Assuming that your application is named example-com and the environment is test, and you may want to save all your logs of this application into elasticsearch index named logstash-example-com-test.

There are a few code examples:

# file log_config.py
from easy_logstash import EasyLogstashConfig

log_config = EasyLogstashConfig(
    LOGSTASH_HOST, LOGSTASH_PORT, LOGSTASH_DATABASE_PATH, 'example-com-test'
)


# file foo.py
from log_config import log_config

logger = log_config.get_logger(__name__)
logger.warning('Some things look strangely ...')

It's very simple, right?

Now, take a look at the situation when you use only the package python-logstash-async to do the same thing without easy-logstash for better understanding what easy-logstash does.

# file log_config.py should be involved while application is starting
import logging
from logstash_async.formatter import LogstashFormatter
from logstash_async.handler import AsynchronousLogstashHandler

# create the application root logger with logstash
root_logger = logging.getLogger('logstash-example-com-test')
root_logger.propagate = False
root_logger.setLevel(logging.DEBUG)

# create the handler and formatter
handler = AsynchronousLogstashHandler(LOGSTASH_HOST, LOGSTASH_PORT, LOGSTASH_DATABASE_PATH)
formatter = LogstashFormatter(metadata={'elasticsearch_index': 'logstash-example-com-test'})
handler.setFormatter(formatter)
handler.setLevel(logging.DEBUG)

# add handler to the application root logger
root_logger.addHandler(handler)


# create your log in your file foo.py
logger = logging.getLogger(f'logstash-example-com-test.{__name__}')
logger.warning('Some things look strangely ...')

Django

You can also configure the constant LOGGING in your setting.py file in a very simple way.

# setting.py
...
from easy_logstash import DjangoLogstashConfig

LOGGING_CONFIG = DjangoLogstashConfig(
    LOGSTASH_HOST, LOGSTASH_PORT, LOGSTASH_DATABASE_PATH, 'example-com-test'
)
LOGGING = LOGGING_CONFIG.get_dict_config()
...

# foo.py
from django.conf import settings

logger = settings.LOGGING_CONFIG.get_logger(__name__)
logger.warning('Some things look strangely ...')

Logstash pipeline configuration

For example, the logstash pipeline configuration would look like this:

input {
	beats {
		port => 5044
	}

	tcp {
		port => 50000
	}
}

## Add your filters / logstash plugins configuration here
filter {
  json {
    source => "message"
    #add_field => {"log_time" => " %{@timestamp}"}
  }
}

output {
	elasticsearch {
		hosts => "elasticsearch:9200"
		user => "logstash_internal"
		password => "strong_password"
		index => "%{[@metadata][elasticsearch_index]}"
	}
}

That's all. Enjoy coding!

Metadata

Release files for easy-logstash 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easy-logstash 1.0.0
File Size Uploaded
easy_logstash-1.0.0.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easy-logstash 1.0.0
File Interpreter ABI Platform
easy_logstash-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / easy_logstash-1.0.0.tar.gz

Download URL easy_logstash-1.0.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
80fea22ece5abbf6989740551b5424b7eb0d7e738ad6a40ceb73137bd3f671a8
BLAKE2b-256 checksum
How to use checksums
dc15cf5721e944d2606de9dbe0bad933bd4fb52fc6beb142d76621477d11f1a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / easy_logstash-1.0.0-py3-none-any.whl

Download URL easy_logstash-1.0.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba64f87ce2871da6867e1af5b7870e40fb7df7dd5632ba238f051800da9b493e
BLAKE2b-256 checksum
How to use checksums
7e02c6bcd79dc1c49eaf7d720795f897ea6ca58f8bfdd325148d570987f7e860
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page