Using the default loggersedit

By default, the client creates a "warning" level, Console or Stdio logger. To change this, specify the client’s log: config value to either an array of logger config’s, a single logger config, a log level, an array of log levels, or a constructor for your own logger. That’s a lot of options, so here is an example of each.

Change the logging level to trace, so we get every log message.

var client = new elasticsearch.Client({ log: 'trace' });

Change the logging level, only listen for error and trace messages.

var client = new elasticsearch.Client({ log: ['error', 'trace'] });

Log every message to a file.

var client = new elasticsearch.Client({
  log: {
    type: 'file',
    level: 'trace',
    path: '/var/log/elasticsearch.log'
  }
});

Log everything to a file and errors to a socket.

var client = new elasticsearch.Client({
  log: [
    {
      type: 'stream',
      level: 'error',
      // config option specific to stream type loggers
      stream: mySocket
    },
    {
      type: 'file',
      level: 'trace',
      // config options specific to file type loggers
      path: '/var/log/elasticsearch.log'
    }
  ]
});

Logger Typesedit

"stdio"

The default logger for in Node, writes log messages for "info", "debug", and "trace" to stdout and "error" and "warning" to stderr.

Options:

color
Boolean — Write with a bit of flair. The default value is intelligently chosen by chalk based on the details of your environment. Default is true.

"file"

Append the log messages to a file.

Options:

path
String — Location of the file to write log messages to. It is created if it does not exists. Default is "elasticsearch.log"

"tracer"

Logs in a format that can be executed with bash, where everything is commented except the trace commands which are formatted as curl calls. By default all of the urls are rewritten to protect production systems and to making the scripts easier to reuse/send to other people. In order to control the urls written specify the curlHost and curlPort configs.

Options:

curlHost
String —  Default is "localhost".
curlPort
String —  Default is 9200.

"stream"

Send log messages to a WriteableStream

Options:

stream
WriteableStream — object to write to.

"console"

Default logger for the browser build, logs to the console when one exists.