[fix](log) use logger to replace printStackTrace() (#17382)

Use Logger to replace printStackTrace to better locate problems.
This commit is contained in:
WenYao
2023-03-03 14:51:30 +08:00
committed by GitHub
parent cc5fa509ad
commit b5b595519a
27 changed files with 84 additions and 63 deletions

View File

@ -179,7 +179,7 @@ public class PaloFe {
Thread.sleep(2000);
}
} catch (Throwable e) {
e.printStackTrace();
LOG.warn("", e);
}
}
@ -245,7 +245,7 @@ public class PaloFe {
try {
cmd = commandLineParser.parse(options, args);
} catch (final ParseException e) {
e.printStackTrace();
LOG.warn("", e);
System.err.println("Failed to parse command line. exit now");
System.exit(-1);
}
@ -357,7 +357,7 @@ public class PaloFe {
System.out.println("Load image success. Image file " + cmdLineOpts.getImagePath() + " is valid");
} catch (Exception e) {
System.out.println("Load image failed. Image file " + cmdLineOpts.getImagePath() + " is invalid");
e.printStackTrace();
LOG.warn("", e);
} finally {
System.exit(0);
}

View File

@ -469,7 +469,7 @@ public class SelectStmt extends QueryStmt {
tableRef.setOnClause(expr.trySubstitute(mvSMap, analyzer, false));
}
} catch (Exception e) {
e.printStackTrace();
LOG.warn("", e);
}
}
}

View File

@ -1000,7 +1000,7 @@ public class Env {
Thread.sleep(5000);
continue;
} catch (InterruptedException e) {
e.printStackTrace();
LOG.warn("", e);
System.exit(-1);
}
}
@ -1347,7 +1347,7 @@ public class Env {
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
LOG.warn("", e);
}
}
}

View File

@ -18,6 +18,8 @@
package org.apache.doris.clone;
import com.google.common.collect.Lists;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@ -31,6 +33,7 @@ import java.util.concurrent.atomic.AtomicLong;
* A simple statistic of tablet checker and scheduler
*/
public class TabletSchedulerStat {
private static final Logger LOG = LogManager.getLogger(TabletSchedulerStat.class);
@Target({ ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@ -132,7 +135,7 @@ public class TabletSchedulerStat {
((AtomicLong) field.get(lastSnapshot)).set(((AtomicLong) field.get(this)).get());
}
} catch (ClassNotFoundException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
LOG.warn("", e);
lastSnapshot = null;
}
}
@ -157,7 +160,7 @@ public class TabletSchedulerStat {
result.add(info);
}
} catch (ClassNotFoundException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
LOG.warn("", e);
return Lists.newArrayList();
}
return result;
@ -183,7 +186,7 @@ public class TabletSchedulerStat {
sb.append(current).append(" (+").append(current - last).append(")\n");
}
} catch (ClassNotFoundException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
LOG.warn("", e);
return "";
}

View File

@ -101,7 +101,7 @@ public class BDBHA implements HAProtocol {
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
LOG.warn("", e1);
}
}
}

View File

@ -19,6 +19,8 @@ package org.apache.doris.httpv2.config;
import org.apache.doris.common.Log4jConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.boot.logging.LogFile;
import org.springframework.boot.logging.LoggingInitializationContext;
@ -34,7 +36,7 @@ import java.io.File;
@Component
public class ReadEnvironment implements ApplicationContextAware {
private static final Logger LOG = LogManager.getLogger(ReadEnvironment.class);
private ApplicationContext applicationContext;
@Override
@ -59,7 +61,7 @@ public class ReadEnvironment implements ApplicationContextAware {
system.initialize(new LoggingInitializationContext(environment),
logConfig, logFile);
} catch (Exception ex) {
ex.printStackTrace();
LOG.warn("", ex);
}
}

View File

@ -22,6 +22,8 @@ import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@ -33,7 +35,7 @@ import java.util.Map;
@RestController
@RequestMapping("/rest/v1")
public class ConfigController {
private static final Logger LOG = LogManager.getLogger(ConfigController.class);
private static final List<String> CONFIG_TABLE_HEADER = Lists.newArrayList("Name", "Value");
@RequestMapping(path = "/config/fe", method = RequestMethod.GET)
@ -57,7 +59,7 @@ public class ConfigController {
list.add(info);
}
} catch (Exception e) {
e.printStackTrace();
LOG.warn("", e);
}
}
}

View File

@ -24,6 +24,8 @@ import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.persist.Storage;
import org.apache.doris.system.Frontend;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@ -39,6 +41,7 @@ import java.util.Map;
@RestController
@RequestMapping("/rest/v1")
public class HaController {
private static final Logger LOG = LogManager.getLogger(HaController.class);
@RequestMapping(path = "/ha", method = RequestMethod.GET)
public Object ha() {
@ -145,7 +148,7 @@ public class HaController {
result.put("CheckpointInfo", list);
} catch (IOException e) {
e.printStackTrace();
LOG.warn("", e);
}
}

View File

@ -104,7 +104,6 @@ public class LogController {
content.put("LogConfiguration", map);
} catch (IOException e) {
LOG.error(e);
e.printStackTrace();
}
}

View File

@ -25,6 +25,8 @@ import org.apache.doris.metric.PrometheusMetricVisitor;
import org.apache.doris.metric.SimpleCoreMetricVisitor;
import com.google.common.base.Strings;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -36,7 +38,7 @@ import javax.servlet.http.HttpServletResponse;
//fehost:port/metrics?type=core
@RestController
public class MetricsAction extends RestBaseController {
private static final Logger LOG = LogManager.getLogger(MetricsAction.class);
private static final String TYPE_PARAM = "type";
@RequestMapping(path = "/metrics")
@ -58,7 +60,7 @@ public class MetricsAction extends RestBaseController {
try {
response.getWriter().write(MetricRepo.getMetric(visitor));
} catch (IOException e) {
e.printStackTrace();
LOG.warn("", e);
}
}

View File

@ -138,14 +138,14 @@ public class RestBaseController extends BaseController {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
LOG.warn("", e);
}
}
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
LOG.warn("", e);
}
}
}

View File

@ -201,7 +201,7 @@ public class BDBEnvironment {
try {
Thread.sleep(5 * 1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
LOG.warn("", e1);
}
} else {
LOG.error("error to open replicated environment. will exit.", e);
@ -342,7 +342,7 @@ public class BDBEnvironment {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
LOG.warn("", e1);
}
} catch (DatabaseException e) {
LOG.warn("catch an exception when calling getDatabaseNames", e);
@ -421,7 +421,7 @@ public class BDBEnvironment {
try {
Thread.sleep(5 * 1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
LOG.warn("", e1);
}
} else {
LOG.error("error to open replicated environment. will exit.", e);

View File

@ -156,7 +156,7 @@ public class BDBJEJournal implements Journal { // CHECKSTYLE IGNORE THIS LINE: B
try {
Thread.sleep(5 * 1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
LOG.warn("", e1);
}
}
}
@ -221,7 +221,7 @@ public class BDBJEJournal implements Journal { // CHECKSTYLE IGNORE THIS LINE: B
try {
ret.readFields(in);
} catch (IOException e) {
e.printStackTrace();
LOG.warn("", e);
}
} else {
System.out.println("No record found for key '" + journalId + "'.");

View File

@ -33,6 +33,8 @@ import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.LockMode;
import com.sleepycat.je.OperationStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@ -44,7 +46,7 @@ import java.util.List;
import java.util.Map;
public class BDBTool {
private static final Logger LOG = LogManager.getLogger(BDBTool.class);
private String metaPath;
private BDBToolOptions options;
@ -63,7 +65,7 @@ public class BDBTool {
try {
env = new Environment(new File(metaPath), envConfig);
} catch (DatabaseException e) {
e.printStackTrace();
LOG.warn("", e);
System.err.println("Failed to open BDBJE env: " + Env.getCurrentEnv().getBdbDir() + ". exit");
return false;
}
@ -129,7 +131,7 @@ public class BDBTool {
}
}
} catch (Exception e) {
e.printStackTrace();
LOG.warn("", e);
System.err.println("Failed to run bdb tools");
return false;
}
@ -152,7 +154,7 @@ public class BDBTool {
try {
entity.readFields(in);
} catch (Exception e) {
e.printStackTrace();
LOG.warn("", e);
System.err.println("Fail to read journal entity for key: " + key + ". reason: " + e.getMessage());
System.exit(-1);
}

View File

@ -21,6 +21,8 @@ import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.PrimitiveType;
import com.google.common.base.Strings;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
@ -28,6 +30,7 @@ import java.nio.ByteBuffer;
// used for serialize memory data to byte stream of MySQL protocol
public class MysqlSerializer {
private static final Logger LOG = LogManager.getLogger(MysqlSerializer.class);
private ByteArrayOutputStream out;
private MysqlCapability capability;
@ -134,7 +137,7 @@ public class MysqlSerializer {
writeVInt(buf.length);
writeBytes(buf);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
LOG.warn("", e);
}
}
@ -143,7 +146,7 @@ public class MysqlSerializer {
byte[] buf = value.getBytes("UTF-8");
writeBytes(buf);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
LOG.warn("", e);
}
}
@ -153,7 +156,7 @@ public class MysqlSerializer {
writeBytes(buf);
writeByte((byte) 0);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
LOG.warn("", e);
}
}

View File

@ -32,6 +32,8 @@ import org.apache.doris.nereids.properties.RequestPropertyDeriver;
import org.apache.doris.nereids.stats.StatsCalculator;
import com.google.common.collect.Lists;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
@ -42,6 +44,7 @@ import java.util.Optional;
* Inspired by NoisePage and ORCA-Paper.
*/
public class CostAndEnforcerJob extends Job implements Cloneable {
private static final Logger LOG = LogManager.getLogger(CostAndEnforcerJob.class);
// GroupExpression to optimize
private final GroupExpression groupExpression;
@ -314,7 +317,7 @@ public class CostAndEnforcerJob extends Job implements Cloneable {
// TODO: need to implement this method
job = (CostAndEnforcerJob) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
LOG.warn("", e);
throw new RuntimeException("clone cost and enforcer job failed.");
}
return job;

View File

@ -1935,7 +1935,7 @@ public class ShowExecutor {
dynamicPartitionProperty.getSortedReservedHistoryPeriods(unsortedReservedHistoryPeriods,
dynamicPartitionProperty.getTimeUnit().toUpperCase())));
} catch (DdlException e) {
e.printStackTrace();
LOG.warn("", e);
} finally {
olapTable.readUnlock();
}

View File

@ -525,7 +525,6 @@ public class StmtExecutor implements ProfileWriter {
Env.getCurrentEnv().getSqlBlockRuleMgr().matchSql(
originStmt.originStmt, context.getSqlHash(), context.getQualifiedUser());
} catch (AnalysisException e) {
e.printStackTrace();
LOG.warn(e.getMessage());
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
return;
@ -618,21 +617,19 @@ public class StmtExecutor implements ProfileWriter {
context.getState().setError(ErrorCode.ERR_NOT_SUPPORTED_YET, "Do not support this query.");
}
} catch (IOException e) {
e.printStackTrace();
LOG.warn("execute IOException. {}", context.getQueryIdentifier(), e);
// the exception happens when interact with client
// this exception shows the connection is gone
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, e.getMessage());
throw e;
} catch (UserException e) {
e.printStackTrace();
LOG.warn("", e);
// analysis exception only print message, not print the stack
LOG.warn("execute Exception. {}, {}", context.getQueryIdentifier(),
e.getMessage());
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
context.getState().setErrType(QueryState.ErrType.ANALYSIS_ERR);
} catch (Exception e) {
e.printStackTrace();
LOG.warn("execute Exception. {}", context.getQueryIdentifier(), e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR,
e.getClass().getSimpleName() + ", msg: " + Util.getRootCauseMessage(e));
@ -649,7 +646,6 @@ public class StmtExecutor implements ProfileWriter {
sessionVariable.setIsSingleSetVar(false);
sessionVariable.clearSessionOriginValue();
} catch (DdlException e) {
e.printStackTrace();
LOG.warn("failed to revert Session value. {}", context.getQueryIdentifier(), e);
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
}
@ -825,7 +821,6 @@ public class StmtExecutor implements ProfileWriter {
if (parsedStmt instanceof LogicalPlanAdapter) {
throw new NereidsException(new AnalysisException("Unexpected exception: " + e.getMessage(), e));
}
e.printStackTrace();
throw new AnalysisException("Unexpected exception: " + e.getMessage());
} finally {
MetaLockUtils.readUnlockTables(tables);
@ -1047,7 +1042,7 @@ public class StmtExecutor implements ProfileWriter {
SetExecutor executor = new SetExecutor(context, setStmt);
executor.execute();
} catch (DdlException e) {
e.printStackTrace();
LOG.warn("", e);
// Return error message to client.
context.getState().setError(ErrorCode.ERR_LOCAL_VARIABLE, e.getMessage());
return;
@ -1724,7 +1719,7 @@ public class StmtExecutor implements ProfileWriter {
try {
context.getEnv().changeCatalog(context, switchStmt.getCatalogName());
} catch (DdlException e) {
e.printStackTrace();
LOG.warn("", e);
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
return;
}
@ -1758,7 +1753,7 @@ public class StmtExecutor implements ProfileWriter {
}
context.getEnv().changeDb(context, useStmt.getDatabase());
} catch (DdlException e) {
e.printStackTrace();
LOG.warn("", e);
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
return;
}
@ -1927,15 +1922,13 @@ public class StmtExecutor implements ProfileWriter {
DdlExecutor.execute(context.getEnv(), (DdlStmt) parsedStmt);
context.getState().setOk();
} catch (QueryStateException e) {
e.printStackTrace();
LOG.warn("", e);
context.setState(e.getQueryState());
} catch (UserException e) {
e.printStackTrace();
// Return message to info client what happened.
LOG.debug("DDL statement({}) process failed.", originStmt.originStmt, e);
LOG.warn("DDL statement({}) process failed.", originStmt.originStmt, e);
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
} catch (Exception e) {
e.printStackTrace();
// Maybe our bug
LOG.warn("DDL statement(" + originStmt.originStmt + ") process failed.", e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, "Unexpected exception: " + e.getMessage());
@ -1949,7 +1942,7 @@ public class StmtExecutor implements ProfileWriter {
context.getEnv().changeCluster(context, enterStmt.getClusterName());
context.setDatabase("");
} catch (DdlException e) {
e.printStackTrace();
LOG.warn("", e);
context.getState().setError(e.getMysqlErrorCode(), e.getMessage());
return;
}
@ -1968,7 +1961,6 @@ public class StmtExecutor implements ProfileWriter {
DdlExecutor.execute(context.getEnv(), ctasStmt);
context.getState().setOk();
} catch (Exception e) {
e.printStackTrace();
// Maybe our bug
LOG.warn("CTAS create table error, stmt={}", originStmt.originStmt, e);
context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, "Unexpected exception: " + e.getMessage());

View File

@ -134,7 +134,6 @@ public class ColumnStatistic {
columnStatisticBuilder.setSelectivity(1.0);
return columnStatisticBuilder.build();
} catch (Exception e) {
e.printStackTrace();
LOG.warn("Failed to deserialize column statistics, column not exists", e);
return ColumnStatistic.DEFAULT;
}

View File

@ -98,7 +98,6 @@ public class Histogram {
return histogramBuilder.build();
} catch (Exception e) {
e.printStackTrace();
LOG.warn("Failed to deserialize histogram statistics.", e);
return Histogram.DEFAULT;
}