<commit_before><?php
  //
  // Simple class for printing traces to a file.
  //
  // To print a trace:
  //
  //   require_once('lib/debug/Tracer.php');
  //   $tracer->trace('some_trace_id', "Hello world");
  //
  // This will print the following to the trace file
  //
  //   -- some_trace_id: Hello world
  //
  // But only if tracing is active for id 'some_trace_id' is active.
  // By default, all traces are inactive.
  // To activate them, you must add the following to db/local.php
  //
  //    $tiki_traces_are_on = true;
  //    $tiki_traces_fpath = '/some/path/that/is/writeable/by/apache.txt';
  //    $tiki_traces_active_ids =
  //       array(
  //           'some_trace_id_that_you_want_to_be_active',
  //           'some_other_trace_id_that_you_want_to_be_active',
  //           etc...
  //       );
  //
  // To deactivate an individual trace, simply remove it from the $tiki_traces_active_ids
  // in db/local.php.
  //
  // To deactivate all traces in one go, set $tiki_traces_are_on = false in db/local.php.
  //
class Tracer
{

	public $traces_are_on = false;
	public $trace_file_path = NULL;
	public $tiki_trace_active_ids = NULL;

	public function __construct($trace_file_path, $traces_are_on=false, $traces_active_ids)
	{
		$this->trace_file_path = $trace_file_path;
		$this->traces_are_on = $traces_are_on;
		$this->tiki_trace_active_ids = array_merge($traces_active_ids, array());
		if ($trace_file_path != NULL) {
			file_put_contents($this->trace_file_path, '');
		}
	}

	public function trace($trace_id, $message)
	{
		if ($this->traces_are_on && $this->trace_file_path != NULL &&
			in_array($trace_id, $this->tiki_trace_active_ids)) {
			file_put_contents($this->trace_file_path, "-- $trace_id: $message\n", FILE_APPEND);
		}
	}

	//
	// Method for pretty printing a data structure as a "human readable"
	// JSON string
	//
	function pretty_print($in, $indent = 0, Closure $_escape = null)
	{
        //
        // Pretty printing of a large data structure can consume time if it is called often.
        // We wouldn't want that to happen in a production context where some traces were
        // left behind in the code.
        // To avoid this, we only do the pretty_print if traces are on.<commit_msg>[FIX] Warning was raised by Tracer.php when no traces defined in local.php.<commit_after><?php
  //
  // Simple class for printing traces to a file.
  //
  // To print a trace:
  //
  //   require_once('lib/debug/Tracer.php');
  //   $tracer->trace('some_trace_id', "Hello world");
  //
  // This will print the following to the trace file
  //
  //   -- some_trace_id: Hello world
  //
  // But only if tracing is active for id 'some_trace_id' is active.
  // By default, all traces are inactive.
  // To activate them, you must add the following to db/local.php
  //
  //    $tiki_traces_are_on = true;
  //    $tiki_traces_fpath = '/some/path/that/is/writeable/by/apache.txt';
  //    $tiki_traces_active_ids =
  //       array(
  //           'some_trace_id_that_you_want_to_be_active',
  //           'some_other_trace_id_that_you_want_to_be_active',
  //           etc...
  //       );
  //
  // To deactivate an individual trace, simply remove it from the $tiki_traces_active_ids
  // in db/local.php.
  //
  // To deactivate all traces in one go, set $tiki_traces_are_on = false in db/local.php.
  //
class Tracer
{

	public $traces_are_on = false;
	public $trace_file_path = NULL;
	public $tiki_trace_active_ids = NULL;

	public function __construct($trace_file_path, $traces_are_on=false, $traces_active_ids)
	{
		$this->trace_file_path = $trace_file_path;
		$this->traces_are_on = $traces_are_on;
        if (isset($traces_active_ids))
        {
            $this->tiki_trace_active_ids = array_merge($traces_active_ids, array());
        }
        else
        {
            $this->tiki_trace_active_ids = array();
        }
		$this->tiki_trace_active_ids = array_merge($traces_active_ids, array());
		if ($trace_file_path != NULL) {
			file_put_contents($this->trace_file_path, '');
		}
	}

	public function trace($trace_id, $message)
	{
		if ($this->traces_are_on && $this->trace_file_path != NULL &&
			in_array($trace_id, $this->tiki_trace_active_ids)) {
			file_put_contents($this->trace_file_path, "-- $trace_id: $message\n", FILE_APPEND);
		}
	}

	//
	// Method for pretty printing a data structure as a "human readable"
	// JSON string
	//
	function pretty_print($in, $indent = 0, Closure $_escape = null)
	{
        //
        // Pretty printing of a large data structure can consume time if it is called often.
        // We wouldn't want that to happen in a production context where some traces were
        // left behind in the code.
        // To avoid this, we only do the pretty_print if traces are on.
{'fraction_non_alphanumeric': 0.12329628853009017, 'fraction_numerical': 0.0004193751310547285, 'mean_word_length': 2.7529504327301337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1417020', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1627, 'n_words': 412}