easy-logstash


Nameeasy-logstash JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/ptbang/Easy-Logstash
SummaryA easy way to handle logs with logstash.
upload_time2024-04-16 09:40:54
maintainerBang Phan
docs_urlNone
authorBang Phan (ptbang)
requires_pythonNone
licenseMIT
keywords logstash logging async easy simple
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/eht16/python-logstash-async/tree/49635e1fdac463329196f44693735070c5275231)
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:

```python
# 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.

```python
# 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.

```python
# 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!*

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ptbang/Easy-Logstash",
    "name": "easy-logstash",
    "maintainer": "Bang Phan",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "logstash logging async easy simple",
    "author": "Bang Phan (ptbang)",
    "author_email": "ptbang@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/dc/15/cf5721e944d2606de9dbe0bad933bd4fb52fc6beb142d76621477d11f1a3/easy_logstash-1.0.0.tar.gz",
    "platform": null,
    "description": "# Easy Logstash\n\nEasy Logstash is a python package that allows you to use logstash logging\nin your applications in very simple manner.\n\nBecause of using [Python logstash async](https://github.com/eht16/python-logstash-async/tree/49635e1fdac463329196f44693735070c5275231)\non the background, you can read more about the python logstash async at the link above.\n\n## Installation\n Just `pip install easy-logstash`\n\n## Usage\nAssuming that your application is named `example-com` and the environment is `test`,\nand you may want to save all your logs of this application\ninto elasticsearch index named `logstash-example-com-test`.\n\nThere are a few code examples:\n\n```python\n# file log_config.py\nfrom easy_logstash import EasyLogstashConfig\n\nlog_config = EasyLogstashConfig(\n    LOGSTASH_HOST, LOGSTASH_PORT, LOGSTASH_DATABASE_PATH, 'example-com-test'\n)\n\n\n# file foo.py\nfrom log_config import log_config\n\nlogger = log_config.get_logger(__name__)\nlogger.warning('Some things look strangely ...')\n```\n\nIt's very simple, right?\n\nNow, take a look at the situation when you use only the package `python-logstash-async`\nto do the same thing without `easy-logstash`\nfor better understanding what `easy-logstash` does.\n\n```python\n# file log_config.py should be involved while application is starting\nimport logging\nfrom logstash_async.formatter import LogstashFormatter\nfrom logstash_async.handler import AsynchronousLogstashHandler\n\n# create the application root logger with logstash\nroot_logger = logging.getLogger('logstash-example-com-test')\nroot_logger.propagate = False\nroot_logger.setLevel(logging.DEBUG)\n\n# create the handler and formatter\nhandler = AsynchronousLogstashHandler(LOGSTASH_HOST, LOGSTASH_PORT, LOGSTASH_DATABASE_PATH)\nformatter = LogstashFormatter(metadata={'elasticsearch_index': 'logstash-example-com-test'})\nhandler.setFormatter(formatter)\nhandler.setLevel(logging.DEBUG)\n\n# add handler to the application root logger\nroot_logger.addHandler(handler)\n\n\n# create your log in your file foo.py\nlogger = logging.getLogger(f'logstash-example-com-test.{__name__}')\nlogger.warning('Some things look strangely ...')\n```\n\n### Django\nYou can also configure the constant LOGGING in your `setting.py` file in a very simple way.\n\n```python\n# setting.py\n...\nfrom easy_logstash import DjangoLogstashConfig\n\nLOGGING_CONFIG = DjangoLogstashConfig(\n    LOGSTASH_HOST, LOGSTASH_PORT, LOGSTASH_DATABASE_PATH, 'example-com-test'\n)\nLOGGING = LOGGING_CONFIG.get_dict_config()\n...\n\n# foo.py\nfrom django.conf import settings\n\nlogger = settings.LOGGING_CONFIG.get_logger(__name__)\nlogger.warning('Some things look strangely ...')\n```\n\n## Logstash pipeline configuration\nFor example, the logstash pipeline configuration would look like this:\n\n```\ninput {\n\tbeats {\n\t\tport => 5044\n\t}\n\n\ttcp {\n\t\tport => 50000\n\t}\n}\n\n## Add your filters / logstash plugins configuration here\nfilter {\n  json {\n    source => \"message\"\n    #add_field => {\"log_time\" => \" %{@timestamp}\"}\n  }\n}\n\noutput {\n\telasticsearch {\n\t\thosts => \"elasticsearch:9200\"\n\t\tuser => \"logstash_internal\"\n\t\tpassword => \"strong_password\"\n\t\tindex => \"%{[@metadata][elasticsearch_index]}\"\n\t}\n}\n```\n\n\n*That's all. Enjoy coding!*\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A easy way to handle logs with logstash.",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://github.com/ptbang/Easy-Logstash",
        "Homepage": "https://github.com/ptbang/Easy-Logstash"
    },
    "split_keywords": [
        "logstash",
        "logging",
        "async",
        "easy",
        "simple"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e02c6bcd79dc1c49eaf7d720795f897ea6ca58f8bfdd325148d570987f7e860",
                "md5": "d92d318a3f29111990eff9cdb62b47d3",
                "sha256": "ba64f87ce2871da6867e1af5b7870e40fb7df7dd5632ba238f051800da9b493e"
            },
            "downloads": -1,
            "filename": "easy_logstash-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d92d318a3f29111990eff9cdb62b47d3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6442,
            "upload_time": "2024-04-16T09:40:53",
            "upload_time_iso_8601": "2024-04-16T09:40:53.039516Z",
            "url": "https://files.pythonhosted.org/packages/7e/02/c6bcd79dc1c49eaf7d720795f897ea6ca58f8bfdd325148d570987f7e860/easy_logstash-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dc15cf5721e944d2606de9dbe0bad933bd4fb52fc6beb142d76621477d11f1a3",
                "md5": "f579abf550f020840562ee00e4387c7c",
                "sha256": "80fea22ece5abbf6989740551b5424b7eb0d7e738ad6a40ceb73137bd3f671a8"
            },
            "downloads": -1,
            "filename": "easy_logstash-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f579abf550f020840562ee00e4387c7c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5468,
            "upload_time": "2024-04-16T09:40:54",
            "upload_time_iso_8601": "2024-04-16T09:40:54.893533Z",
            "url": "https://files.pythonhosted.org/packages/dc/15/cf5721e944d2606de9dbe0bad933bd4fb52fc6beb142d76621477d11f1a3/easy_logstash-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 09:40:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ptbang",
    "github_project": "Easy-Logstash",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "easy-logstash"
}
        
Elapsed time: 0.24473s