2020-10-06 16:15:07 +00:00
|
|
|
/*
|
2022-10-17 21:08:52 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-10-06 16:15:07 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2022-10-17 21:08:52 +00:00
|
|
|
package org.geysermc.geyser.platform.fabric;
|
2020-10-06 16:15:07 +00:00
|
|
|
|
2022-10-24 17:21:02 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
2020-10-06 17:41:50 +00:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2021-12-02 16:08:25 +00:00
|
|
|
import org.geysermc.geyser.GeyserLogger;
|
2022-10-24 17:21:02 +00:00
|
|
|
import org.geysermc.geyser.text.ChatColor;
|
2020-10-06 16:15:07 +00:00
|
|
|
|
|
|
|
public class GeyserFabricLogger implements GeyserLogger {
|
2020-10-06 17:41:50 +00:00
|
|
|
private final Logger logger = LogManager.getLogger("geyser-fabric");
|
|
|
|
|
2020-10-06 16:15:07 +00:00
|
|
|
private boolean debug;
|
|
|
|
|
|
|
|
public GeyserFabricLogger(boolean isDebug) {
|
|
|
|
debug = isDebug;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void severe(String message) {
|
2020-10-06 17:41:50 +00:00
|
|
|
logger.fatal(message);
|
2020-10-06 16:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void severe(String message, Throwable error) {
|
2020-10-06 17:41:50 +00:00
|
|
|
logger.fatal(message, error);
|
2020-10-06 16:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(String message) {
|
2020-10-06 17:41:50 +00:00
|
|
|
logger.error(message);
|
2020-10-06 16:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void error(String message, Throwable error) {
|
2020-10-06 17:41:50 +00:00
|
|
|
logger.error(message, error);
|
2020-10-06 16:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void warning(String message) {
|
2020-10-06 17:41:50 +00:00
|
|
|
logger.warn(message);
|
2020-10-06 16:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void info(String message) {
|
2020-10-06 17:41:50 +00:00
|
|
|
logger.info(message);
|
2020-10-06 16:15:07 +00:00
|
|
|
}
|
|
|
|
|
2022-10-24 17:21:02 +00:00
|
|
|
@Override
|
|
|
|
public void sendMessage(Component message) {
|
|
|
|
// As of Java Edition 1.19.2, Fabric's console doesn't natively support legacy format
|
|
|
|
String flattened = LegacyComponentSerializer.legacySection().serialize(message);
|
|
|
|
// Add the reset at the end, or else format will persist... forever.
|
|
|
|
// https://cdn.discordapp.com/attachments/573909525132738590/1033904509170225242/unknown.png
|
|
|
|
String text = ChatColor.toANSI(flattened) + ChatColor.ANSI_RESET;
|
|
|
|
info(text);
|
|
|
|
}
|
|
|
|
|
2020-10-06 16:15:07 +00:00
|
|
|
@Override
|
|
|
|
public void debug(String message) {
|
|
|
|
if (debug) {
|
2020-10-06 17:41:50 +00:00
|
|
|
logger.info(message);
|
2020-10-06 16:15:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setDebug(boolean debug) {
|
|
|
|
this.debug = debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isDebug() {
|
|
|
|
return debug;
|
|
|
|
}
|
|
|
|
}
|