package fr.insa.clavardator.lib.util;

import org.jetbrains.annotations.Nullable;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Log {
	/**
	 * Verbose level: 0 = nothing,
	 * 1: errors,
	 * 2: errors & warnings,
	 * 3: errors & warnings & debug,
	 * 4: all
	 */
	public static int verboseLevel = 4;

	private static void print(String prefix, String message, String mode, int requiredLevel, @Nullable Exception e) {
		if (verboseLevel >= requiredLevel) {
			Date date = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
			System.out.println(sdf.format(date) + " | " + mode + " | " + prefix + ": " + message);
			if (e != null)
				e.printStackTrace();
		}
	}

	public static void v(String prefix, String message) {
		v(prefix, message, null);
	}

	public static void v(String prefix, String message, Exception e) {
		print(prefix, message, "V", 4, e);
	}

	public static void d(String prefix, String message) {
		d(prefix, message, null);
	}

	public static void d(String prefix, String message, Exception e) {
		print(prefix, message, "D", 3, e);
	}

	public static void w(String prefix, String message) {
		w(prefix, message, null);
	}

	public static void w(String prefix, String message, Exception e) {
		print(prefix, message, "W", 2, e);
	}

	public static void e(String prefix, String message) {
		e(prefix, message, null);
	}

	public static void e(String prefix, String message, Exception e) {
		print(prefix, message, "E", 1, e);
	}
}
