001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.http.codec; 018 019import org.apache.commons.logging.Log; 020 021import org.springframework.http.HttpLogging; 022 023/** 024 * Base class for {@link org.springframework.core.codec.Encoder}, 025 * {@link org.springframework.core.codec.Decoder}, {@link HttpMessageReader}, or 026 * {@link HttpMessageWriter} that uses a logger and shows potentially sensitive 027 * request data. 028 * 029 * @author Rossen Stoyanchev 030 * @since 5.1 031 */ 032public class LoggingCodecSupport { 033 034 protected final Log logger = HttpLogging.forLogName(getClass()); 035 036 /** Whether to log potentially sensitive info (form data at DEBUG and headers at TRACE). */ 037 private boolean enableLoggingRequestDetails = false; 038 039 040 /** 041 * Whether to log form data at DEBUG level, and headers at TRACE level. 042 * Both may contain sensitive information. 043 * <p>By default set to {@code false} so that request details are not shown. 044 * @param enable whether to enable or not 045 */ 046 public void setEnableLoggingRequestDetails(boolean enable) { 047 this.enableLoggingRequestDetails = enable; 048 } 049 050 /** 051 * Whether any logging of values being encoded or decoded is explicitly 052 * disabled regardless of log level. 053 */ 054 public boolean isEnableLoggingRequestDetails() { 055 return this.enableLoggingRequestDetails; 056 } 057 058}