[Enhancement](multi-catalog) Set hdfs native client logger to glog and redirect jvm stdout/stderr logger to jni.log. (#41633)
Backport #39540. Co-authored-by: Mingyu Chen <morningman@163.com>
This commit is contained in:
@ -17,10 +17,15 @@
|
||||
|
||||
package org.apache.doris.common.classloader;
|
||||
|
||||
import org.apache.doris.common.jni.utils.Log4jOutputStream;
|
||||
|
||||
import com.google.common.collect.Streams;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@ -48,6 +53,7 @@ public class ScannerLoader {
|
||||
* Load all classes from $DORIS_HOME/lib/java_extensions/*
|
||||
*/
|
||||
public void loadAllScannerJars() {
|
||||
redirectStdStreamsToLog4j();
|
||||
String basePath = System.getenv("DORIS_HOME");
|
||||
File library = new File(basePath, "/lib/java_extensions/");
|
||||
// TODO: add thread pool to load each scanner
|
||||
@ -60,6 +66,16 @@ public class ScannerLoader {
|
||||
});
|
||||
}
|
||||
|
||||
private void redirectStdStreamsToLog4j() {
|
||||
Logger outLogger = Logger.getLogger("stdout");
|
||||
PrintStream logPrintStream = new PrintStream(new Log4jOutputStream(outLogger, Level.INFO));
|
||||
System.setOut(logPrintStream);
|
||||
|
||||
Logger errLogger = Logger.getLogger("stderr");
|
||||
PrintStream errorPrintStream = new PrintStream(new Log4jOutputStream(errLogger, Level.ERROR));
|
||||
System.setErr(errorPrintStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get loaded class for JNI scanners
|
||||
* @param className JNI scanner class name
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you 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.
|
||||
|
||||
package org.apache.doris.common.jni.utils;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class Log4jOutputStream extends OutputStream {
|
||||
private final Logger logger;
|
||||
private final StringBuilder buffer = new StringBuilder();
|
||||
private final Level level;
|
||||
|
||||
public Log4jOutputStream(Logger logger, Level level) {
|
||||
this.logger = logger;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) {
|
||||
if (b == '\n') {
|
||||
logger.log(level, buffer.toString());
|
||||
buffer.setLength(0);
|
||||
} else {
|
||||
buffer.append((char) b);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user