<commit_before><?php

namespace Terminus;

use Terminus\JLogger as Logger;
use Psr\Log\LogLevel;

//TODO: Change this classname to Logger once the old logger is fully replaced
class KLogger extends Logger {
  protected $parent;

  /**
   * Class constructor. Feeds in output destination from env vars
   *
   * @param [array]  $options           Options for operation of logger
   *        [array] config Configuration options from Runner
   * @param [string] $logDirectory      File path to the logging directory
   * @param [string] $logLevelThreshold The LogLevel Threshold
   * @return [KLogger] $this
   */
  public function __construct(
    array $options = array(),
    $logDirectory = 'php://stderr',
    $logLevelThreshold = LogLevel::INFO
  ) {
    $config = $options['config'];
    unset($options['config']);

    if (isset($_SERVER['TERMINUS_LOG_DIR'])) {
      $logDirectory = $_SERVER['TERMINUS_LOG_DIR'];
    } elseif ($config['silent']) {
      $logDirectory = ini_get('error_log');
    }

    if ($config['debug']) {
      $logLevelThreshold = LogLevel::DEBUG;
    }

    if (!isset($options['logFormat'])) {
      if ($config['json'] != null) {
        $options['logFormat'] = 'json';
      }
      if ($config['bash'] != null) {
        $options['logFormat'] = 'bash';
      }
    }

    parent::__construct($logDirectory, $logLevelThreshold, $options);
    $this->parent = $this->extractParent();
  }

  /**
    * Logs with an arbitrary level.
    *
    * @param [mixed]  $level
    * @param [string] $message
    * @param [array]  $context
    * @return [void]
    */
  public function log($level, $message, array $context = array()) {
    $parent = $this->parent;
    if ($parent->logLevels[$parent->logLevelThreshold] < $parent->logLevels[$level]) {
      return;
    }
    if ($parent->options['logFormat'] == 'json') {
      $message = $this->formatJsonMessages($level, $message, $context);
    } elseif ($parent->options['logFormat'] == 'bash') {
      $message = $this->formatBashMessages($level, $message, $context);
    } else {<commit_msg>Changed logger response in case of silent with no log destination<commit_after><?php

namespace Terminus;

use Terminus\JLogger as Logger;
use Psr\Log\LogLevel;

//TODO: Change this classname to Logger once the old logger is fully replaced
class KLogger extends Logger {
  protected $parent;

  /**
   * Class constructor. Feeds in output destination from env vars
   *
   * @param [array]  $options           Options for operation of logger
   *        [array] config Configuration options from Runner
   * @param [string] $logDirectory      File path to the logging directory
   * @param [string] $logLevelThreshold The LogLevel Threshold
   * @return [KLogger] $this
   */
  public function __construct(
    array $options = array(),
    $logDirectory = 'php://stderr',
    $logLevelThreshold = LogLevel::INFO
  ) {
    $config = $options['config'];
    unset($options['config']);

    if ($config['debug']) {
      $logLevelThreshold = LogLevel::DEBUG;
    }

    if (!isset($options['logFormat'])) {
      if ($config['json'] != null) {
        $options['logFormat'] = 'json';
      }
      if ($config['bash'] != null) {
        $options['logFormat'] = 'bash';
      }
    }

    if (isset($_SERVER['TERMINUS_LOG_DIR'])) {
      $logDirectory = $_SERVER['TERMINUS_LOG_DIR'];
    } elseif ($config['silent']) {
      $logDirectory = ini_get('error_log');
      if ($logDirectory == '') {
        die(
          'You must either set error_log in your php.ini, or define '
          . ' TERMINUS_LOG_DIR to use silent mode.' . PHP_EOL
        );
      }
    }

    parent::__construct($logDirectory, $logLevelThreshold, $options);
    $this->parent = $this->extractParent();
  }

  /**
    * Logs with an arbitrary level.
    *
    * @param [mixed]  $level
    * @param [string] $message
    * @param [array]  $context
    * @return [void]
    */
  public function log($level, $message, array $context = array()) {
    $parent = $this->parent;
    if ($parent->logLevels[$parent->logLevelThreshold] < $parent->logLevels[$level]) {
      return;
    }
    if ($parent->options['logFormat'] == 'json') {
      $message = $this->formatJsonMessages($level, $message, $context);
    } elseif ($parent->options['logFormat'] == 'bash') {
      $message = $this->formatBashMessages($level, $message, $context);
    } else {
{'fraction_non_alphanumeric': 0.15386368816959198, 'fraction_numerical': 0.0, 'mean_word_length': 3.074280408542247, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5866938', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1307, 'n_words': 339}