package core.utils.logs;

import com.sun.net.httpserver.HttpExchange;
import core.utils.io.IOFileWriter;

import java.time.LocalDateTime;

public class Logger
{
    private static final String PATH = "resources/logs.txt";
    private static final IOFileWriter writer = new IOFileWriter();

    public static void info(String message)
    {
        message = "| INFO - " + LocalDateTime.now() + " - " + message;

        System.out.println(message);
        writer.append(PATH, message);
    }

    public static void error(String message)
    {
        message = "| ERROR - " + LocalDateTime.now() + " - " + message;

        System.out.println(message);
        writer.append(PATH, message);
    }

    public static void info(HttpExchange exchange)
    {
        String message = "%s %s %s".formatted
        (
                exchange.getRequestURI(),
                exchange.getRemoteAddress(),
                exchange.getRequestMethod()
        );
        info(message);
    }
}