kutuluk / loglevel-plugin-remote

A loglevel plugin for sending browser logs to a server
MIT License
102 stars 36 forks source link

Configure property name `queue.content` if JSON mode #31

Open jnnwnk opened 4 years ago

jnnwnk commented 4 years ago

We'd like to send the log messages to a CouchDB. Bulk insert is supported by CouchDB. But the payload requires a property named docs (instead of logs).

What about a config value for property name (see https://github.com/kutuluk/loglevel-plugin-remote/blob/master/src/remote.js#L272)

Something like (not tested, might be buggy and is more like pseudo code)

if (isJSON) {
  let logsPropertyName = config.logPropertyName || "logs"
  queue.content = {}
  queue.content[logsPropertyName] = [${logs.join(',')}]
} else {
  queue.content = logs.join('\n')
}