/* * ATLauncher - https://github.com/ATLauncher/ATLauncher * Copyright (C) 2013 ATLauncher * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package co.forsaken.projectindigo.log; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import co.forsaken.projectindigo.log.LogEvent.LogType; import co.forsaken.projectindigo.utils.LoggingThread; import co.forsaken.projectindigo.utils.Utils; public final class LogManager { private static final BlockingQueue<LogEvent> queue = new ArrayBlockingQueue<LogEvent>(128); public static boolean showDebug = false; public static int debugLevel = 0; private static final LoggingThread thread = new LoggingThread(queue); private LogManager() {} public static void start() { thread.start(); } public static void join() { try { thread.join(); } catch (InterruptedException e) {} } public static void log(LogEvent event) { queue.offer(event); } public static void info(String message) { queue.offer(new LogEvent(LogEvent.LogType.INFO, message)); } public static void debug(String message) { debug(message, false); } public static void debug(String message, boolean force) { if (showDebug || force) { queue.offer(new LogEvent(LogEvent.LogType.DEBUG, message)); } } public static void debug(String message, int level) { if (showDebug || debugLevel >= level) { queue.offer(new LogEvent(LogEvent.LogType.DEBUG, message)); } } public static void warn(String message) { queue.offer(new LogEvent(LogEvent.LogType.WARN, message)); } public static void error(String message) { queue.offer(new LogEvent(LogEvent.LogType.ERROR, message)); } public static void minecraft(String message) { Object[] value = Utils.prepareMessageForMinecraftLog(message); queue.offer(new LogEvent((LogType) value[0], (String) value[1], 10)); } }