Comments (8)
Hutool的log使用第三方Log框架,并根据引入包自动识别。
请检查第三方日志配置的info和error是否打开。
from hutool.
Hutool的log使用第三方Log框架,并根据引入包自动识别。
请检查第三方日志配置的info和error是否打开。
我截图里面是能够正常打印各个级别的日志,我问的是为什么没有异常堆栈信息,throw 的异常或者其他未捕获的未知异常都没有打印异常堆栈信息。
from hutool.
@Mr-LiuDC sorry,理解错了。
要打印堆栈,需要传入Exception对象:
log.error(e, msg);
from hutool.
你说的传入 Exception 对象是没问题的,下面这行没有打印堆栈是什么问题呢?
throw new RuntimeException(msg);
from hutool.
我举个例子,我在 Action 里面用 DBUtil 进行数据库的读写操作,当报了异常,如果没有手动进行 catch 异常并手动打印异常,控制台居然没有打印任何异常信息。
from hutool.
@Mr-LiuDC 终于明白你的意思了。
在Action中抛出异常是会被吃掉
的。
这个原因是 com. sun. net. httpserver
中HttpHandler
的创建处理机制并不抛出异常,此时需要你自定义com.sun.net.httpserver.Filter
或cn.hutool.http.server.filter.HttpFilter
/**
* 异常处理过滤器
*
* @author looly
*/
public abstract class ExceptionFilter implements HttpFilter {
@Override
public void doFilter(final HttpServerRequest req, final HttpServerResponse res, final Filter.Chain chain) {
try {
chain.doFilter(req.getHttpExchange());
} catch (final Throwable e) {
afterException(req, res, e);
}
}
/**
* 异常之后的处理逻辑
*
* @param req {@link HttpServerRequest}
* @param res {@link HttpServerResponse}
* @param e 异常
*/
public abstract void afterException(final HttpServerRequest req, final HttpServerResponse res, final Throwable e);
}
from hutool.
这块6.x做的比较完善,5.8.8会增加ExceptionFilter
和DefaultExceptionFilter
。
这样有了异常会打印在页面中:
public class ExceptionServerTest {
public static void main(final String[] args) {
HttpUtil.createServer(8888)
.addFilter(new DefaultExceptionFilter())
.addAction("/", (req, res) -> {
throw new RuntimeException("Test Exception");
})
.start();
}
}
from hutool.
@looly 非常感谢你的耐心解答。
from hutool.
Related Issues (20)
- 利用 JSR-305 元注释向支持 JSR-305 的常用工具指示 Java 中的可为空性 HOT 2
- Cannot read the array length because "<local3>" is null HOT 6
- 读取文件超过3GB时报java.lang.NegativeArraySizeException: -221445712 HOT 1
- 关于@Alias注解的一些使用建议 HOT 1
- NumberWordFormatter.format 只有1位小数转英文有BUG HOT 1
- BeanUtil.setProperty 希望表达式可以支持list直接设置值 HOT 4
- Performance issue of Snowflake HOT 1
- org.dromara.hutool.http.HttpUtil#get(java.lang.String) 请求无法成功 HOT 1
- hutool-cache key有效期的使用方式 HOT 1
- 希望能增加一个经纬度处理的工具 HOT 2
- DateUtil.format能否支持增加参数Locale 格式化成其他语言 HOT 1
- 关于ListUtil#setOrPadding的安全检查 HOT 2
- BooleanUtil.andOfWrap针对null取与结果与预期不符 HOT 1
- JSONObject.toBean为null问题 HOT 2
- 图片添加文字水印可以支持45度倾斜多行重复文字的效果么 HOT 1
- cn.hutool.core.io.FileUtil#getTotalLines 在jdk8和jdk21中结果不一致 HOT 1
- cn.hutool.http.HttpUtil#post(java.lang.String, java.lang.String) 这个方法按文档的标准参数调用报异常 HOT 5
- HttpRequest 设置body的时候能否修改isMultiPart的值。 HOT 4
- 需求请求:LocalDateTimeUtil.endOfDay重载一个接收LocalDate的方法 HOT 3
- get请求https时会出现ssl证书问题 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hutool.