<commit_before>'use strict'

const config = require('config')

const logAPI = module.exports = {}

logAPI.get = function *() {
  var token

  // TODO: Add support for session cookie authentication.

  token = this.token

  // Check necessary if fields are provided.
  if (!token._id) this.throw('User id is required.', 400)
  if (!log) this.throw('Log has no content.', 400)

  var payload = {
    topic: config.kafkaTopic,
    messages: log
  }

  // Commit logs to kafka.
  yield this.kafkaClient.send([payload])

  this.body = {
    token: token,
    log: log
  }
}<commit_msg>Add additional information in kafka payload<commit_after>'use strict'

const config = require('config')
const kafka = require('kafka-node')
const KeyedMessage = kafka.KeyedMessage

const logAPI = module.exports = {}

logAPI.get = function *() {
  var token

  // TODO: Add support for session cookie authentication.

  token = this.token

  // Check necessary if fields are provided.
  if (!token._id) this.throw('User id is required.', 400)
  var log = this.query.log
  if (!log) this.throw('Log has no content.', 400)

  var logMessage = new KeyedMessage('log', log)
  var idMessage = new KeyedMessage('_id', token._id)
  var payload = {
    topic: config.kafkaTopic,
    messages: [logMessage, idMessage],
    partition: parseInt(this.query.partition, 10) || 0,
    attributes: parseInt(this.query.attributes, 10) || 0
  }

  // Commit logs to kafka.
  yield this.kafkaClient.send([payload])

  this.body = {
    token: token,
    log: log,
    userID: token._id
  }
}
{'fraction_non_alphanumeric': 0.1276595744680851, 'fraction_numerical': 0.01160541586073501, 'mean_word_length': 3.299168975069252, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1002501', 'n_tokens_mistral': 512, 'n_tokens_neox': 482, 'n_words': 151}