/* This file is a part of the SteamWar software. Copyright (C) 2020 SteamWar.de-Serverteam This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package de.steamwar.core; import de.steamwar.sql.SWException; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.*; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; @Plugin(name = "ErrorLogger", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) public class ErrorLogger extends AbstractAppender { public static void init(){ final LoggerContext lc = (LoggerContext) LogManager.getContext(false); ErrorLogger el = ErrorLogger.createAppender("SWErrorLogger"); el.start(); lc.getConfiguration().addAppender(el); lc.getRootLogger().addAppender(lc.getConfiguration().getAppender(el.getName())); lc.updateLoggers(); } private ErrorLogger(String name) { super(name, null, null); } @PluginFactory public static ErrorLogger createAppender( @PluginAttribute("name") String name) { return new ErrorLogger(name); } @Override public void append(LogEvent logEvent) { if(logEvent.getLevel().isLessSpecificThan(Level.WARN)) return; SWException.log(logEvent); } }