0

looking at this example

client.execute{search in "places"->"cities" query "paris" start 5 limit 10}

is there an option to hook logging to client.execute to log all operations made by the client (index, search etc') ?

I saw this answer but I do not want to do something like :

val req = search in "index" / "type" query "kate bush"
logger.debug(s"Search request ${req.show}")

I want the client to log all base on the logging level

Community
  • 1
  • 1
igx
  • 4,101
  • 11
  • 43
  • 88
  • If you enable the DEBUG level in your logging configuration then you'll see some more output about whats' going on internally. – Val Jan 24 '17 at 12:32
  • @Val thanks, it is enabled but I do not see any elastic4s output – igx Jan 24 '17 at 13:04
  • How did you enable it? – Val Jan 24 '17 at 13:04
  • @Val in my build sbt file ```logLevel in run := Level.Debug``` – igx Jan 24 '17 at 13:36
  • @Val also tried adding this ```import org.elasticsearch.common.logging.ESLoggerFactory ESLoggerFactory.getRootLogger.setLevel("debug")``` But didn't really help – igx Jan 24 '17 at 13:53
  • Elastic4s doesn't do much logging, but version 5.2.0 does a bit more. – sksamuel Feb 02 '17 at 00:59

1 Answers1

0

You can define your own ElasticClient, with overriding execute functionality

object MyElasticClientFactory {
     def fromClient(client: Client): ElasticClient = new ElasticClient {
     def close(): Unit = client.close()
     def java: Client = client

     override def execute[T, R, Q](request: T)(implicit executable: Executable[T, R, Q]): Future[Q] = {
         // TODO your logging here
         super.execute(request)
     }

}

Take a look at TcpClient for reference https://github.com/sksamuel/elastic4s/blob/9a4074b6ff5616b648801352b4c3629cd0fc9020/elastic4s-tcp/src/main/scala/com/sksamuel/elastic4s/TcpClient.scala

mavarazy
  • 7,562
  • 1
  • 34
  • 60