Transform Message object to a string
@param {object} msg
@param {string|function} formatter
@param {object} [electronLog]
@param {boolean} [removeStyles=false]
@return {string}
function format(msg, formatter, electronLog, removeStyles) {
  removeStyles = removeStyles !== undefined ? removeStyles : false;

  if (typeof formatter === 'function') {
    return formatter(msg, electronLog);
  }

  var date = new Date(msg.date || Date.now());
  var variables = msg.variables;
  var result = formatter;

  for (var i in variables) {
    if (!variables.hasOwnProperty(i)) continue;
    result = result.replace('{' + i + '}', variables[i]);
  }

  result = result
    .replace('{level}', msg.level)
    .replace('{text}', stringifyArray(msg.data))
    .replace('{y}', String(date.getFullYear()))
    .replace('{m}', pad(date.getMonth() + 1))
    .replace('{d}', pad(date.getDate()))
    .replace('{h}', pad(date.getHours()))
    .replace('{i}', pad(date.getMinutes()))
    .replace('{s}', pad(date.getSeconds()))
    .replace('{ms}', pad(date.getMilliseconds(), 3))
    .replace('{z}', formatTimeZone(date.getTimezoneOffset()));

  if (removeStyles) {
    result = result.replace(/%c/g, '');
  }

  return result;
}