记录400错误消息

时间:2016-10-13 06:32:12

标签: apache logging

在生产环境中,当我请求我的网页时。请求显示在apache的访问日志中,但不会显示在配置的我配置的Web日志中。

我的logback.xml是

 <configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<jmxConfigurator />
<property name="CONSOLE_LOG_PATTERN"
    value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p ${PID:- } --- [%15.15t{14}] %-40.40logger{0} : %m%n" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>/var/log/company_name/payments.log</file>
    <encoder>
        <pattern>${CONSOLE_LOG_PATTERN}</pattern>
    </encoder>
</appender>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>${CONSOLE_LOG_PATTERN}</pattern>
    </encoder>
</appender>

<root level="INFO">
    <appender-ref ref="FILE" />
</root>

我的控制器是

@CrossOrigin
@RestController
@RequestMapping("/my/v1")
public class PaymentApi {

@RequestMapping(value = RestURIConstants.VOID_TRANSACTION, 
                method = RequestMethod.POST )
public @ResponseBody ResponseEntity<?> voidPayment(@RequestParam("request") String voidRequestJson,
                                                   HttpServletRequest httpServletRequest) {
  //Code here.
 }

    @ExceptionHandler
     void handleException(Exception e, HttpServletResponse response) throws IOException {
        logger.error("Error in Request : " + new ObjectMapper().writeValueAsString(e));
        if (e instanceof IllegalArgumentException) {
        response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());
        return;
        }
        response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), "an error occured while processing request");
    }

 }

我正在使用以下代码制作网络请求。

 public static <T extends Response,S extends Request> T doPostRequest(S request,
                                                              Class<T> responseClass,
                                                              String urlString) throws ClientProtocolException, IOException{
    RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    logger.info("Sending Request " + objectMapper.writeValueAsString(request));
    HttpEntity<String> entity = new HttpEntity<String>("request=" + objectMapper.writeValueAsString(request), headers);
    ResponseEntity<String> response = null ;

    response = restTemplate.exchange(urlString, HttpMethod.POST, entity, String.class);

    logger.info("Response recieved " + response.toString());
    if (response.getStatusCode() == HttpStatus.OK || 
            response.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
        return  objectMapper.readValue(response.getBody(), responseClass) ;
            //  gson.fromJson(response.getBody(), responseClass) ;
    }else{
        return  objectMapper.readValue(response.getBody(), responseClass) ;
    }
  }

相同的代码适用于我的本地,但在生产中它会抛出400错误,而且payment.log文件中也没有日志。

我的支付服务器上正在生产的Java版本是1.8.0_25,发出这些请求的服务器是1.8.0_91。

我无法确定原因,因为payment.log

中没有针对此网络请求的日志

1 个答案:

答案 0 :(得分:0)

他们对生产中的标题大小有限制。因为我遇到了这个问题而且payment.log中没有日志。