<commit_before>package uk.gov.homeoffice.logging

import java.io.{ByteArrayOutputStream, PrintStream}
import scala.collection.mutable

trait ConsoleLogging {
  val outputStreams = mutable.Map[Thread, ByteArrayOutputStream]()

  def consoleLog = outputStreams(Thread.currentThread()).toString

  def withConsoleRedirect[T](block: => T) = {
    val baos = new ByteArrayOutputStream
    outputStreams.update(Thread.currentThread(), baos)

    val ps = new PrintStream(baos)

    val sysOutOriginal = System.out
    val sysErrorOriginal = System.err

    System.setOut(ps)
    System.setErr(ps)

    val result = block

    System.setOut(sysOutOriginal)
    System.setErr(sysErrorOriginal)
    outputStreams.remove(Thread.currentThread())

    result
  }
}<commit_msg>Restrict use of ConsoleLogging to avoid thread usage and thereby be safer to use.<commit_after>package uk.gov.homeoffice.logging

import java.io.{ByteArrayOutputStream, PrintStream}
import org.specs2.matcher.Scope

trait ConsoleLogging {
  this: Scope =>

  val baos = new ByteArrayOutputStream

  val ps = new PrintStream(baos)

  def consoleLog = baos.toString

  def withConsoleRedirect[T](block: => T) = {
    val sysOutOriginal = System.out
    val sysErrorOriginal = System.err

    System.setOut(ps)
    System.setErr(ps)

    val result = block

    System.setOut(sysOutOriginal)
    System.setErr(sysErrorOriginal)

    result
  }
}
{'fraction_non_alphanumeric': 0.08967971530249111, 'fraction_numerical': 0.0007117437722419929, 'mean_word_length': 4.075812274368231, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4262943', 'n_tokens_mistral': 438, 'n_tokens_neox': 421, 'n_words': 96}