<?php
/**
 * Logging, on top of WooCommerce's own logger.
 *
 * @package Ordsync
 */

defined( 'ABSPATH' ) || exit;

/**
 * Never build your own log system. WooCommerce already has a good one.
 */
class Ordsync_Logger {

	const SOURCE = 'order-sync';

	/**
	 * Info level.
	 *
	 * @param string $message Message.
	 * @return void
	 */
	public static function info( $message ) {
		self::write( 'info', $message );
	}

	/**
	 * Warning level.
	 *
	 * @param string $message Message.
	 * @return void
	 */
	public static function warning( $message ) {
		self::write( 'warning', $message );
	}

	/**
	 * Error level.
	 *
	 * @param string $message Message.
	 * @return void
	 */
	public static function error( $message ) {
		self::write( 'error', $message );
	}

	/**
	 * Write a line.
	 *
	 * @param string $level   Log level.
	 * @param string $message Message.
	 * @return void
	 */
	private static function write( $level, $message ) {
		if ( ! function_exists( 'wc_get_logger' ) ) {
			return;
		}
		wc_get_logger()->log( $level, $message, array( 'source' => self::SOURCE ) );
	}

	/**
	 * Where the [View Logs] button points.
	 *
	 * @return string
	 */
	public static function admin_url() {
		return admin_url( 'admin.php?page=wc-status&tab=logs' );
	}
}
