You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Elasticsearch version (bin/elasticsearch --version):
Version: 8.6.2, Build: docker/2d58d0f136141f03239816a4e360a8d17b6d8f29/2023-02-13T09:35:20.314882762Z, JVM: 19.0.2 elasticsearch-py version (elasticsearch.__versionstr__):
'8.6.2'
Description of the problem including expected versus actual behavior:
I want to send all the logs to ES so I created a log handler that sends all logs to an index.
The problem is for every post request the library makes to ES to save the log, another log gets written and it becomes an infinite loop of logs that spams the server.
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.022s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.050s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.002s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.005s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.005s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:30 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.049s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.002s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.005s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.060s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.002s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.050s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.051s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.004s]
2023-03-13 14:48:31 INFO 28440 POST http://localhost:9200/my_index/_doc [status:201 duration:0.003s]
I found a workaround by running logging.getLogger('elastic_transport.transport').setLevel(logging.WARNING)
Steps to reproduce:
Here is the code to reproduce
import datetime
import logging
import time
from elasticsearch import Elasticsearch
class ElasticsearchHandler(logging.Handler):
def __init__(self):
super().__init__()
self._elasticSearch = None
self._elasticSearch = Elasticsearch("http://localhost:9200")
def emit(self, record: logging.LogRecord):
try:
body = {
"timestamp": datetime.datetime.now(),
"message": record.getMessage()
}
self._elasticSearch.index(index="my_index", document=body)
except Exception:
self.handleError(record)
def close(self):
if self._elasticSearch is not None:
self._elasticSearch.close()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
esHandler = ElasticsearchHandler()
logger.addHandler(esHandler)
logging.info("Hello")
time.sleep(10)
esHandler.close()
The text was updated successfully, but these errors were encountered:
of your ElasticsearchHandler. That means each time the logger is trigger by an endpoint, your handler will call index that will trigger another logger call and so on.
If you want to send log in Elasticsearch the best option is to use Elastic Common Schema (ECS) logger for the Python logging library. We have also an example for this use case here.
Elasticsearch version (
bin/elasticsearch --version
):Version: 8.6.2, Build: docker/2d58d0f136141f03239816a4e360a8d17b6d8f29/2023-02-13T09:35:20.314882762Z, JVM: 19.0.2
elasticsearch-py
version (elasticsearch.__versionstr__
):'8.6.2'
Description of the problem including expected versus actual behavior:
I want to send all the logs to ES so I created a log handler that sends all logs to an index.
The problem is for every post request the library makes to ES to save the log, another log gets written and it becomes an infinite loop of logs that spams the server.
I found a workaround by running
logging.getLogger('elastic_transport.transport').setLevel(logging.WARNING)
Steps to reproduce:
Here is the code to reproduce
The text was updated successfully, but these errors were encountered: