<?php
/**
 * Abstract logger class.
 *
 * @package northmill-online-shared
 */

namespace Northmill_Online_Shared\Modules\Loggers;

use Northmill_Online_Shared\Abstract_Shared_Base;

/**
 * Class Abstract_Logger
 */
abstract class Abstract_Logger {

	/**
	 * Abstract_Logger constructor.
	 *
	 * @param Abstract_Shared_Base $shared  Shared instance.
	 * @param bool                 $enabled Whether the logger is enabled or not.
	 */
	public function __construct(
		protected Abstract_Shared_Base $shared,
		protected bool $enabled = true
	) {}

	/**
	 * Get whether the logger is enabled or not.
	 */
	public function is_enabled(): bool {
		return $this->enabled;
	}

	/**
	 * Set whether the logger is enabled or not.
	 *
	 * @param bool $enabled Whether the logger is enabled or not.
	 */
	public function set_enabled( bool $enabled ): void {
		$this->enabled = $enabled;
	}

	/**
	 * Add a log entry.
	 *
	 * @param string         $channel      The channel to log to.
	 * @param string         $message      The message to be logged.
	 * @param null|array     $context      Optional additional data to be logged.
	 * @param Log_Level_Enum $level        Log level.
	 * @param bool           $external_log Whether the log is external (not from our package) or not.
	 *
	 * @return void
	 */
	abstract public function log(
		string $channel,
		string $message,
		?array $context,
		Log_Level_Enum $level,
		bool $external_log = false
	): void;
}
