<commit_before><?php

namespace Macbre\Logger\Formatters;

/**
 * Custom Nano JSON formatter
 */
class JsonFormatter extends \Monolog\Formatter\JsonFormatter {

	/**
	 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#mapping-date-format
	 */
	const DATE_FORMAT = 'Y-m-d\TH:i:s.uP';

	/**
	 * @param array $record
	 * @return string formatted record
	 */
	public function format(array $record) {
		$entry = [
			'@timestamp' => self::now(),
			'@message' => $record['message'],
			'@context' => (object) $record['context'],
			'@fields' => (object) $record['extra'],
			'severity' => strtolower($record['level_name']),
			'program' => $record['channel'],
			'@source_host' => gethostname(),
		];

		return parent::format($entry);
	}

	/**
	 * Return a elasticsearch compatible timestamp with microseconds
	 *
	 * @see http://stackoverflow.com/a/17909891/5446110
	 * @return string
	 */
	private static function now() {<commit_msg>Stay compatible with Monolog 2.x<commit_after><?php

namespace Macbre\Logger\Formatters;

/**
 * Custom Nano JSON formatter
 */
class JsonFormatter extends \Monolog\Formatter\JsonFormatter {

	/**
	 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#mapping-date-format
	 */
	const DATE_FORMAT = 'Y-m-d\TH:i:s.uP';

	/**
	 * @param array $record
	 * @return string formatted record
	 */
	public function format(array $record): string {
		$entry = [
			'@timestamp' => self::now(),
			'@message' => $record['message'],
			'@context' => (object) $record['context'],
			'@fields' => (object) $record['extra'],
			'severity' => strtolower($record['level_name']),
			'program' => $record['channel'],
			'@source_host' => gethostname(),
		];

		return parent::format($entry);
	}

	/**
	 * Return a elasticsearch compatible timestamp with microseconds
	 *
	 * @see http://stackoverflow.com/a/17909891/5446110
	 * @return string
	 */
	private static function now() {
{'fraction_non_alphanumeric': 0.17887822132390097, 'fraction_numerical': 0.015664477008590198, 'mean_word_length': 4.089974293059126, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1444678', 'n_tokens_mistral': 713, 'n_tokens_neox': 626, 'n_words': 127}