<commit_before>import { Mongo } from 'meteor/mongo';
import { logger } from '/imports/utils/logger';


class EventLogClass extends Mongo.Collection {
  addEvent(event) {
    const doc = {
      type: event.getType(),
      message: event.getMessage(),
      createdAt: event.createdAt,
      createdBy: event.userId,
      data: event.data,
    };
    logger.info('New event', doc);
    super.insert(doc);
  }

  queryRecentEvents() {
    return super.find({}, { sort: { createdAt: -1 } });
  }
}

const EventLog = new EventLogClass('eventLog');

const EventSchema = new SimpleSchema({
  type: {
    type: String,
  },
  message: {
    type: String,
    optional: true,
  },
  createdAt: {
    type: Date,
  },
  createdBy: {
    type: String,
  },
  data: {
    type: Object,
    optional: true,
    blackbox: true,
  },
});

EventLog.schema = EventSchema;
EventLog.attachSchema(EventLog.schema);

export default EventLog;
<commit_msg>escape keys in event data<commit_after>import { Mongo } from 'meteor/mongo';
import { logger } from '/imports/utils/logger';
import { escapeKeys } from '/imports/api/utils';



class EventLogClass extends Mongo.Collection {
  addEvent(event) {
    const doc = {
      type: event.getType(),
      message: event.getMessage(),
      createdAt: event.createdAt,
      createdBy: event.userId,
      data: escapeKeys(event.data),
    };
    logger.info('New event', doc);
    super.insert(doc);
  }

  queryRecentEvents() {
    return super.find({}, { sort: { createdAt: -1 } });
  }
}

const EventLog = new EventLogClass('eventLog');

const EventSchema = new SimpleSchema({
  type: {
    type: String,
  },
  message: {
    type: String,
    optional: true,
  },
  createdAt: {
    type: Date,
  },
  createdBy: {
    type: String,
  },
  data: {
    type: Object,
    optional: true,
    blackbox: true,
  },
});

EventLog.schema = EventSchema;
EventLog.attachSchema(EventLog.schema);

export default EventLog;

{'fraction_non_alphanumeric': 0.14182939362795477, 'fraction_numerical': 0.0010277492291880781, 'mean_word_length': 3.0144329896907216, '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': '5373670', 'n_tokens_mistral': 646, 'n_tokens_neox': 638, 'n_words': 148}