File tree Expand file tree Collapse file tree
java/org/baeldung/spring43/composedmapping
test/java/org/baeldung/spring43/composedmapping Expand file tree Collapse file tree Original file line number Diff line number Diff line change 164164 <artifactId >ehcache</artifactId >
165165 <version >${ehcache.version} </version >
166166 </dependency >
167+
168+ <dependency >
169+ <groupId >org.apache.logging.log4j</groupId >
170+ <artifactId >log4j-api</artifactId >
171+ <version >${log4j.version} </version >
172+ </dependency >
173+ <dependency >
174+ <groupId >org.apache.logging.log4j</groupId >
175+ <artifactId >log4j-core</artifactId >
176+ <version >${log4j.version} </version >
177+ </dependency >
178+
167179 </dependencies >
168180
169181 <dependencyManagement >
264276 <assertj .version>3.6.1</assertj .version>
265277 <jasperreports .version>6.4.0</jasperreports .version>
266278
279+ <log4j .version>2.8.2</log4j .version>
280+
267281 </properties >
268282
269283</project >
Original file line number Diff line number Diff line change 66import org .springframework .stereotype .Controller ;
77import org .springframework .web .bind .annotation .GetMapping ;
88import org .springframework .web .bind .annotation .RequestMapping ;
9+ import org .apache .logging .log4j .Logger ;
910
1011@ Controller
1112@ RequestMapping ("/appointments" )
1213public class AppointmentsController {
1314
14- private final AppointmentService appointmentService ;
15+ private AppointmentService appointmentService ;
16+
17+ @ Autowired
18+ private Logger logger ;
1519
1620 @ Autowired
1721 public AppointmentsController (AppointmentService appointmentService ) {
@@ -20,6 +24,7 @@ public AppointmentsController(AppointmentService appointmentService) {
2024
2125 @ GetMapping
2226 public Map <String , Appointment > get () {
27+ logger .info ("Getting appointments..." );
2328 return appointmentService .getAppointmentsForToday ();
2429 }
2530
Original file line number Diff line number Diff line change 1+ rootLogger.level =info
2+ rootLogger.appenderRefs = stdout
3+ rootLogger.appenderRef.stdout.ref = STDOUT
4+
5+ appenders =console
6+
7+ appender.console.type = Console
8+ appender.console.name = STDOUT
9+ appender.console.layout.type = PatternLayout
10+ appender.console.layout.pattern = %p %d{yyyy-MM-dd} [%t] %c{1} - %msg%n
11+
Original file line number Diff line number Diff line change 99import org .springframework .web .servlet .ViewResolver ;
1010import org .springframework .web .servlet .config .annotation .EnableWebMvc ;
1111import org .springframework .web .servlet .view .InternalResourceViewResolver ;
12+ import org .springframework .beans .factory .InjectionPoint ;
13+ import org .apache .logging .log4j .LogManager ;
14+ import org .apache .logging .log4j .Logger ;
15+ import org .springframework .context .annotation .Scope ;
1216
1317import static org .easymock .EasyMock .*;
1418
@@ -33,4 +37,10 @@ public AppointmentService appointmentBook() {
3337 return book ;
3438 }
3539
40+ @ Bean
41+ @ Scope ("prototype" )
42+ public Logger logger (InjectionPoint injectionPoint ) {
43+ return LogManager .getLogger (injectionPoint .getField ().getDeclaringClass ());
44+ }
45+
3646}
You can’t perform that action at this time.
0 commit comments