在某些故意发生的情况下,我使用了一些例外来拒绝该消息,但在控制台中显示异常,第一眼看上去并不正常。
如何隐藏登录控制台/文件的特定异常
我正在使用spring-boot和默认记录器!
// Prepare a select statement
$sql = "SELECT * FROM pupils WHERE pupil_id = ?";
if($stmt = $mysqli->prepare($sql)){
// Bind variables to the prepared statement as parameters
$stmt->bind_param("i", $param_pupil_id);
// Set parameters
$param_pupil_id = $_POST['pupil_num'];
// Attempt to execute the prepared statement
if($stmt->execute()){
$stmt->store_result();
if($stmt->num_rows == 1){
$stmt->bind_result($id, $pupil_id, $name, $eal, $pp);
//Updated code
echo $stmt->fetch()->$name;
} else{
echo "error";
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
这里是listner
public static class UndispatchException extends
AmqpRejectAndDontRequeueException{
public UndispatchException() {
super("Dispatch still looking for a driver");
}
}
这是我要隐藏的日志!在某些情况下,哪个mandetory必须重新排列消息!
@RabbitListener(queues = TEST_QUEUE)
public void handle(Dispatch in) {
if(in.isRequeue()){
log.debug("will reject the message");
throw new UndispatchException();
}
log.debug("won't reject the message");
}
答案 0 :(得分:1)
在日志记录配置中,设置
的日志级别org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler
到ERROR(该消息以WARN级别记录)。
使用Spring Boot,您只需添加...
logging.level.org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler=ERROR
...到您的application.properties(或.yml)文件。
修改强>
如果您希望执行其他操作(例如记录某些例外情况),您可以复制ConditionalRejectingErrorHandler
并在handleError()
方法中进行更改。 code is here。
然后,您将使用自定义错误处理程序配置侦听器容器(或侦听器容器工厂)。