<commit_before>const mongodb = require('mongodb').MongoClient
const logger = require('./logger.js')

const url = 'mongodb://localhost:27017/gw2api'
let database

function connect () {
  return new Promise((resolve, reject) => {
    mongodb.connect(url, (err, db) => {
      if (err) {
        logger.error('Failed connecting to mongodb: ', err.message)
        return reject(err)
      }

      database = db
      logger.info('Connection established to ' + url)
      resolve()
    })
  })
}

function collection (name) {
  return database.collection(name)
}

module.exports = {connect, collection}<commit_msg>Log disconnect and reconnect of database<commit_after>const mongodb = require('mongodb').MongoClient
const logger = require('./logger.js')

const url = 'mongodb://localhost:27017/gw2api'
let database

function connect () {
  return new Promise((resolve, reject) => {
    mongodb.connect(url, (err, db) => {
      if (err) {
        logger.error('Failed connecting to mongodb: ', err.message)
        return reject(err)
      }

      database = db
      logger.info('Connection established to ' + url)
      db.on('close', () => logger.error('Connection to mongodb closed'))
      db.on('reconnect', () => logger.info('Connection to mongodb reestablished'))

      resolve()
    })
  })
}

function collection (name) {
  return database.collection(name)
}

module.exports = {connect, collection}
{'fraction_non_alphanumeric': 0.14082503556187767, 'fraction_numerical': 0.008534850640113799, 'mean_word_length': 3.383177570093458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2931247', 'n_tokens_mistral': 433, 'n_tokens_neox': 407, 'n_words': 102}