mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-08 23:17:54 -05:00
Prints configuration overview (#4451)
* print configuration overview at startup Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
This commit is contained in:
@@ -32,6 +32,7 @@ dependencies {
|
||||
api 'org.slf4j:slf4j-api'
|
||||
|
||||
implementation 'com.google.guava:guava'
|
||||
implementation 'org.apache.commons:commons-lang3'
|
||||
implementation 'org.apache.logging.log4j:log4j-core'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl'
|
||||
implementation 'org.xerial.snappy:snappy-java'
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright Hyperledger Besu Contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.util.log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class FramedLogMessage {
|
||||
private static final int MAX_LINE_LENGTH = 100;
|
||||
|
||||
private FramedLogMessage() {}
|
||||
|
||||
public static String generate(final List<String> logLines) {
|
||||
final StringBuilder builder = new StringBuilder("\n");
|
||||
appendHeader(builder);
|
||||
|
||||
logLines.forEach(
|
||||
logLine ->
|
||||
Splitter.fixedLength(76)
|
||||
.split(logLine)
|
||||
.forEach(
|
||||
splitLogLine ->
|
||||
builder.append(
|
||||
String.format(
|
||||
"# %s #\n",
|
||||
StringUtils.rightPad(splitLogLine, MAX_LINE_LENGTH - 4)))));
|
||||
|
||||
appendFooter(builder);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String generateCentered(final List<String> logLines) {
|
||||
final StringBuilder builder = new StringBuilder("\n");
|
||||
appendHeader(builder);
|
||||
|
||||
logLines.forEach(
|
||||
logLine ->
|
||||
builder.append(
|
||||
String.format("#%s#\n", StringUtils.center(logLine, MAX_LINE_LENGTH - 2))));
|
||||
|
||||
appendFooter(builder);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void appendHeader(final StringBuilder builder) {
|
||||
builder.append("#".repeat(MAX_LINE_LENGTH) + "\n").append(emptyLine());
|
||||
}
|
||||
|
||||
private static void appendFooter(final StringBuilder builder) {
|
||||
builder.append(emptyLine()).append("#".repeat(MAX_LINE_LENGTH));
|
||||
}
|
||||
|
||||
private static String emptyLine() {
|
||||
return String.format("#%s#\n", StringUtils.center("", MAX_LINE_LENGTH - 2));
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,14 @@
|
||||
*/
|
||||
package org.hyperledger.besu.util.platform;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Detects OS and VMs.
|
||||
@@ -28,6 +35,7 @@ public class PlatformDetector {
|
||||
private static String _osType;
|
||||
private static String _vm;
|
||||
private static String _arch;
|
||||
private static String _glibc;
|
||||
|
||||
public static String getOSType() {
|
||||
if (_osType == null) {
|
||||
@@ -57,6 +65,14 @@ public class PlatformDetector {
|
||||
return _vm;
|
||||
}
|
||||
|
||||
public static String getGlibc() {
|
||||
if (_glibc == null) {
|
||||
detectGlibc();
|
||||
}
|
||||
|
||||
return _glibc;
|
||||
}
|
||||
|
||||
private static final String UNKNOWN = "unknown";
|
||||
|
||||
private static void detect() {
|
||||
@@ -213,4 +229,43 @@ public class PlatformDetector {
|
||||
}
|
||||
return System.getProperty(value).toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
|
||||
}
|
||||
|
||||
private static void detectGlibc() {
|
||||
final ProcessBuilder processBuilder =
|
||||
new ProcessBuilder("/bin/bash").command("/usr/bin/ldd", "--version");
|
||||
processBuilder.redirectErrorStream(true);
|
||||
|
||||
final StringBuilder rawGlibcVersionBuilder;
|
||||
try {
|
||||
final Process process = processBuilder.start();
|
||||
rawGlibcVersionBuilder = readGlibcVersionStream(process.getInputStream());
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
_glibc = normalizeGLibcVersion(rawGlibcVersionBuilder.toString());
|
||||
}
|
||||
|
||||
private static StringBuilder readGlibcVersionStream(final InputStream iStream)
|
||||
throws IOException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
|
||||
try (BufferedReader bufferedReader =
|
||||
new BufferedReader(new InputStreamReader(iStream, Charset.defaultCharset()))) {
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
builder.append(System.getProperty("line.separator"));
|
||||
}
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static String normalizeGLibcVersion(final String rawGlibcVersion) {
|
||||
final Pattern pattern = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+");
|
||||
final Matcher matcher = pattern.matcher(rawGlibcVersion);
|
||||
|
||||
return matcher.find() ? matcher.group() : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user