<?php
/**
 * Logger Class File
 *
 * To allow logging to files
 */

namespace CarDealerPress\includes\functions;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Logger Class File
 *
 * This class contains functions to log needed parts
 *
 * @package    CarDealerPress
 */
trait Logger {

	/**
	 * Write log file in
	 *
	 * @access  templates
	 *
	 * @param   string $message  Message which needs to log in text file.
	 * @param   string $file_name    File name of log file.
	 */
	public function append_log( $args ) {
		$file_name = $args['file_name'] ?? CDP_LOGS;
		$type      = isset( $args['type'] ) ? $args['type'] . ': ' : '';
		$date      = wp_date( 'Y-m-d H:i:s' );
		$message   = '[' . $date . ']: ' . $type;
		$message  .= $args['message'] . '<br/>';
		if ( file_exists( $file_name ) ) {
			// TODO: need to keep file for 24-36 hours.
			// @codingStandardsIgnoreStart
			error_log( $message, 3, $file_name );
			// @codingStandardsIgnoreEnd
		}

	}

}
