Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed console legacy color support #1105

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions proxy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ tasks {
dependencies {
implementation(project(":velocity-api"))
implementation(project(":velocity-native"))
implementation(project(":velocity-proxy-log4j2-plugin"))

implementation(libs.bundles.log4j)
implementation(libs.kyori.ansi)
Expand Down
4 changes: 4 additions & 0 deletions proxy/log4j2-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
implementation(libs.bundles.log4j)
annotationProcessor(libs.log4j.core)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2023 Velocity Contributors
*
* 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 <https://www.gnu.org/licenses/>.
*/

package com.velocitypowered.proxy.util;

import java.util.List;
import java.util.regex.Pattern;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.layout.PatternLayout;
import org.apache.logging.log4j.core.pattern.ConverterKeys;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import org.apache.logging.log4j.core.pattern.PatternConverter;
import org.apache.logging.log4j.core.pattern.PatternFormatter;
import org.apache.logging.log4j.core.pattern.PatternParser;

/**
* Strip Format Converter.
* Based on <a href="https://github.com/PaperMC/Paper/pull/9313/files#diff-6c1396d60730e7053f0b761bdb487752467c9bc0444a4aac41908376b38a56bdR198-R233">Paper's patch</a>
*/
@Plugin(name = "stripAnsi", category = PatternConverter.CATEGORY)
@ConverterKeys("stripAnsi")
public class StripAnsiConverter extends LogEventPatternConverter {
private static final Pattern ANSI_PATTERN = Pattern.compile("\u001B\\[[;\\d]*m");
private final List<PatternFormatter> formatters;

/**
* Constructs an instance of StripAnsiConverter.
*/
protected StripAnsiConverter(List<PatternFormatter> formatters) {
super("stripAnsi", null);
this.formatters = formatters;
}

@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
int start = toAppendTo.length();
for (final PatternFormatter formatter : formatters) {
formatter.format(event, toAppendTo);
}
String content = toAppendTo.substring(start);
content = ANSI_PATTERN.matcher(content).replaceAll("");

toAppendTo.setLength(start);
toAppendTo.append(content);
}

/**
* Creates a new Instance of this Converter.
*
* @param config the configuration
* @param options the options
* @return a new instance
*/
public static StripAnsiConverter newInstance(Configuration config, String[] options) {
if (options.length != 1) {
LOGGER.error("Incorrect number of options on stripFormat. Expected 1 received "
+ options.length);
return null;
}
PatternParser parser = PatternLayout.createPatternParser(config);
List<PatternFormatter> formatters = parser.parse(options[0]);
return new StripAnsiConverter(formatters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.kyori.adventure.translation.Translator;
import org.jetbrains.annotations.Nullable;


/**
* Velocity Translation Mapper.
*/
Expand Down
6 changes: 3 additions & 3 deletions proxy/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
<TerminalConsole name="TerminalConsole">
<PatternLayout>
<LoggerNamePatternSelector
defaultPattern="%highlightError{[%d{HH:mm:ss} %level] [%logger]: %minecraftFormatting{%msg}%n%xEx}">
defaultPattern="%highlightError{[%d{HH:mm:ss} %level] [%logger]: %msg%n%xEx}">
<!-- Velocity doesn't need a prefix -->
<PatternMatch key="com.velocitypowered."
pattern="%highlightError{[%d{HH:mm:ss} %level]: %minecraftFormatting{%msg}%n%xEx}"/>
pattern="%highlightError{[%d{HH:mm:ss} %level]: %msg%n%xEx}"/>
</LoggerNamePatternSelector>
</PatternLayout>
</TerminalConsole>
<RollingRandomAccessFile name="File" fileName="logs/latest.log"
filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz"
immediateFlush="false">
<PatternLayout
pattern="[%d{HH:mm:ss}] [%t/%level] [%logger]: %minecraftFormatting{%msg}{strip}%n"/>
pattern="[%d{HH:mm:ss}] [%t/%level] [%logger]: %stripAnsi{%msg}%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<OnStartupTriggeringPolicy/>
Expand Down
6 changes: 6 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ sequenceOf(
project(project).projectDir = file(it)
}

// Include Configurate 3
val deprecatedConfigurateModule = ":deprecated-configurate3"
include(deprecatedConfigurateModule)
project(deprecatedConfigurateModule).projectDir = file("proxy/deprecated/configurate3")

// Log4J2 plugin
val log4j2ProxyPlugin = ":velocity-proxy-log4j2-plugin"
include(log4j2ProxyPlugin)
project(log4j2ProxyPlugin).projectDir = file("proxy/log4j2-plugin")