File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
spring-boot-autoconfigure/src
main/java/org/springframework/boot/autoconfigure/web
test/java/org/springframework/boot/autoconfigure/web
spring-boot-docs/src/main/asciidoc Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -1006,6 +1006,7 @@ private void customizeAccessLog(TomcatEmbeddedServletContainerFactory factory) {
1006
1006
this .accesslog .isRequestAttributesEnabled ());
1007
1007
valve .setRotatable (this .accesslog .isRotate ());
1008
1008
valve .setBuffered (this .accesslog .isBuffered ());
1009
+ valve .setFileDateFormat (this .accesslog .getFileDateFormat ());
1009
1010
factory .addEngineValves (valve );
1010
1011
}
1011
1012
@@ -1060,6 +1061,11 @@ public static class Accesslog {
1060
1061
*/
1061
1062
private boolean renameOnRotate ;
1062
1063
1064
+ /**
1065
+ * Date format to place in log file name.
1066
+ */
1067
+ private String fileDateFormat = ".yyyy-MM-dd" ;
1068
+
1063
1069
/**
1064
1070
* Set request attributes for IP address, Hostname, protocol and port used for
1065
1071
* the request.
@@ -1127,6 +1133,14 @@ public void setRenameOnRotate(boolean renameOnRotate) {
1127
1133
this .renameOnRotate = renameOnRotate ;
1128
1134
}
1129
1135
1136
+ public String getFileDateFormat () {
1137
+ return this .fileDateFormat ;
1138
+ }
1139
+
1140
+ public void setFileDateFormat (String fileDateFormat ) {
1141
+ this .fileDateFormat = fileDateFormat ;
1142
+ }
1143
+
1130
1144
public boolean isRequestAttributesEnabled () {
1131
1145
return this .requestAttributesEnabled ;
1132
1146
}
Original file line number Diff line number Diff line change @@ -160,6 +160,29 @@ public void tomcatAccessLogCanBeEnabled() {
160
160
.isInstanceOf (AccessLogValve .class );
161
161
}
162
162
163
+ @ Test
164
+ public void tomcatAccessLogFileDateFormatByDefault () {
165
+ TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory ();
166
+ Map <String , String > map = new HashMap <String , String >();
167
+ map .put ("server.tomcat.accesslog.enabled" , "true" );
168
+ bindProperties (map );
169
+ this .properties .customize (tomcatContainer );
170
+ assertThat (((AccessLogValve ) tomcatContainer .getEngineValves ().iterator ().next ())
171
+ .getFileDateFormat ()).isEqualTo (".yyyy-MM-dd" );
172
+ }
173
+
174
+ @ Test
175
+ public void tomcatAccessLogFileDateFormatCanBeRedefined () {
176
+ TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory ();
177
+ Map <String , String > map = new HashMap <String , String >();
178
+ map .put ("server.tomcat.accesslog.enabled" , "true" );
179
+ map .put ("server.tomcat.accesslog.file-date-format" , "yyyy-MM-dd.HH" );
180
+ bindProperties (map );
181
+ this .properties .customize (tomcatContainer );
182
+ assertThat (((AccessLogValve ) tomcatContainer .getEngineValves ().iterator ().next ())
183
+ .getFileDateFormat ()).isEqualTo ("yyyy-MM-dd.HH" );
184
+ }
185
+
163
186
@ Test
164
187
public void tomcatAccessLogIsBufferedByDefault () {
165
188
TomcatEmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContainerFactory ();
Original file line number Diff line number Diff line change @@ -196,6 +196,7 @@ content into your application; rather pick only the properties that you need.
196
196
server.tomcat.accesslog.buffered=true # Buffer output such that it is only flushed periodically.
197
197
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute.
198
198
server.tomcat.accesslog.enabled=false # Enable access log.
199
+ server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in log file name.
199
200
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
200
201
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
201
202
server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time.
You can’t perform that action at this time.
0 commit comments