<commit_before>package silky.audit

import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.TimeZone
import scala.collection.Map
import silky.MessageFlowId

class MessageFormatter(dateFormat: DateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"),
                       timeZone: TimeZone = TimeZone.getTimeZone("UTC")) {

  dateFormat.setTimeZone(timeZone)

  def format(messageFlowId: MessageFlowId, auditMessage: AuditMessage): String =
    s"""${dateFormat.format(auditMessage.timestamp)} Begin: $messageFlowId
${asLines(auditMessage.headers)}

${auditMessage.payload}

End: $messageFlowId
""".toString

  private def asLines(headers: Map[String, String]) = headers
    .map(header => s"${header._1}: ${header._2}")
    .mkString("\n")
}<commit_msg>Left-padded expected audit messages with a margin<commit_after>package silky.audit

import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.TimeZone
import scala.collection.Map
import silky.MessageFlowId
import silky.audit.MessageFormatter.withoutMargin

class MessageFormatter(dateFormat: DateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"),
                       timeZone: TimeZone = TimeZone.getTimeZone("UTC")) {

  dateFormat.setTimeZone(timeZone)

  def format(messageFlowId: MessageFlowId, auditMessage: AuditMessage): String = withoutMargin(s"""
    |${dateFormat.format(auditMessage.timestamp)} Begin: $messageFlowId
    |${asLines(auditMessage.headers)}
    |
    |${auditMessage.payload}
    |
    |End: $messageFlowId
    |""")

  private def asLines(headers: Map[String, String]) = headers
    .map(header => s"${header._1}: ${header._2}")
    .mkString("\n")
}

object MessageFormatter {
  private[audit] def withoutMargin(text: String) = text.stripMargin.replaceFirst("\n", "")
}
{'fraction_non_alphanumeric': 0.13038674033149172, 'fraction_numerical': 0.0022099447513812156, 'mean_word_length': 4.996688741721854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '365375', 'n_tokens_mistral': 563, 'n_tokens_neox': 555, 'n_words': 107}