Skip to content

GabrielZuany/ElasticSearchLogs

Repository files navigation

Elastichsearch Log Sender


Getting Started

  • Clone this repository:

    git clone https://github.com/GabrielZuany/ElasticSearchLoggs.git
  • Install and run Docker in your machine (for local development).

  • Go to elastic-config and run the compose file to pull the necessary images:

    cd elastic-config
    docker compose up
  • Then await a few seconds and check the 2 urls below:

  • You must see these two windows:

    • Elastic response: elastic response

    • Elastic Interface: elastic interface

  • So now your environment is setted up and ready to receive loggings from your Python application!


Working with Data Views and Indexes:

  • Creating a Data View based in an index pattern: Creating Data View

    Creating Data View

  • Check your new data view and associated indexes! Logs Screen


Sending Logs to Kibana

  • Create and activate the Virtual Environment:

    python -m venv .venv
    .venv/Scripts/Activate.ps1
  • Install the requirements:

    pip install -r requirements.txt
  • Import the ElasticSearchLogging class to your source code and create an object to manipulate logs:

    import ElasticsearchLogs.ElasticsearchLogging as esl
    
    logging_sender = esl.ElasticsearchLogging(
      host="localhost",
      port=9200
      index=DEFAULT_INDEX
    )
  • Once your setted up the host and port (and also index if you already have one), you can just send logs to Kibana:

    import uuid
    
    logger.info(message="Hello World!", user_id=uuid.uuid4())
    
    try:
        res = 1 / 0
    except Exception as e:
        logger.error(message="Error", user_id=uuid.uuid4(), exception=e)
  • Your logs also going to be writen in console.

  • Local logs (Console): local logs


  • Elastic logs: elastic logs elastic logs


License


Final Considerations

  • Made by me (Gabriel Zuany Duarte Vargas)
  • Feel free to sugest new features and fix non mapped bugs
  • Last update: 07/08/2023

About

Python class to send logs to elasticsearch

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages