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

log4J日志配置被覆盖 #219

Open
xiejin90314 opened this issue Mar 1, 2024 · 0 comments
Open

log4J日志配置被覆盖 #219

xiejin90314 opened this issue Mar 1, 2024 · 0 comments

Comments

@xiejin90314
Copy link

版本:
tencentcloud-sdk-java 3.1.87
log4j系列版本: 2.15.0

我生产日志打印一段时间就不打印了,后来分析到问题是每次初始化 AsrClient client = new AsrClient就会把日志级别设置成ERROR...

在类AbstractClient的有参构造函数中

  public AbstractClient(
      String endpoint,
      String version,
      Credential credential,
      String region,
      ClientProfile profile) {
    this.credential = credential;
    this.profile = profile;
    this.endpoint = endpoint;
    this.region = region;
    this.path = "/";
    this.sdkVersion = AbstractClient.SDK_VERSION;
    this.apiVersion = version;
    this.gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
    // 会重置已有的Log4J的配置
    this.log = new Log(getClass().getName(), profile.isDebug());
    warmup();
  }

这段代码里面会覆盖掉当前的系统已经初始化号的log4j配置
new Log()的初始化过程如下:

  public Log(String name, boolean isDebug) {
    logger = Logger.getLogger(name);
    // 系统中log4j配置以其他形式存在
    File file = new File("log4j.properties");
    if (!file.exists()) {
      this.debug = false;
      // 所有log4J重置成默认的,日志的级别变成error!!
      BasicConfigurator.configure();
      logger.warn("The configuration file of log4j does not exist, please refer to tencentcloud-sdk-java/log4j.properties for configuration.");
    } else {
      this.debug = isDebug;
      PropertyConfigurator.configure("log4j.properties");
    }
  }

排查了一上午的问题.
解决方案: 升级tencentcloud-sdk-java到高点的版本,在高版本中 new Log()变成了new TCLog().....
是哪个校招生写的代码..毁我一上午的时间....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant