Grt1228 / chatgpt-java

ChatGPT Java SDK支持流式输出、Gpt插件、联网。支持OpenAI官方所有接口。ChatGPT的Java客户端。OpenAI GPT-3.5-Turb GPT-4 Api Client for Java
https://chatgpt-java.unfbx.com
Apache License 2.0
3.34k stars 816 forks source link

当程序中已经依赖了一个log框架(例如 logback)时,如果再依赖了chatgpt-java,会导致类路径上存在两个slf4j实现,最终导致了如下错误 #157

Closed yjgbg closed 1 year ago

yjgbg commented 1 year ago
SLF4J: Class path contains multiple SLF4J providers.
SLF4J: Found provider [org.slf4j.simple.SimpleServiceProvider@244038d0]
SLF4J: Found provider [ch.qos.logback.classic.spi.LogbackServiceProvider@5680a178]
SLF4J: See https://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual provider is of type [org.slf4j.simple.SimpleServiceProvider@244038d0]
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.simple.SimpleLoggerFactory loaded from file:/Users/weicl/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/2.0.7/bfa4d4dad645a5b11c022ae0043bac2df6cf16b5/slf4j-simple-2.0.7.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.simple.SimpleLoggerFactory

希望可以删除掉默认的slf4j-simple依赖,因为日志框架的选型应当是用户自己的事情

yjgbg commented 1 year ago

已提交pr: https://github.com/Grt1228/chatgpt-java/pull/158

HumorChen commented 1 year ago

+1 我也出现了log冲突

SwainTian commented 1 year ago

+1 我也出现了日志冲突

可以在pom文件里暂时排除掉 image

JsonSong89 commented 1 year ago

+1 日志基于 slf4j-api 打印即可 具体的日志实现由用户自己完成 目前是必须手工排除实现的依赖

Grt1228 commented 1 year ago

@JsonSong89 @yjgbg @HumorChen @SwainTian 谢谢反馈,马上修复