Skip to content

Commit d67e889

Browse files
committed
Add Logger on backend-springboot
1 parent a960a1c commit d67e889

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

backend-springboot/src/main/java/com/ganatan/backend_java/controllers/HealthController.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
import org.springframework.web.bind.annotation.GetMapping;
44
import org.springframework.web.bind.annotation.RestController;
5+
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
59
import java.util.Map;
610

711
@RestController
812
public class HealthController {
9-
13+
14+
private static final Logger logger = LoggerFactory.getLogger(HealthController .class);
15+
1016
@GetMapping("/health")
1117
public Map<String, String> health() {
18+
logger.info("GET / - health");
1219
return Map.of("status", "ok");
1320
}
1421
}

backend-springboot/src/main/java/com/ganatan/backend_java/controllers/RootController.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
import org.springframework.beans.factory.annotation.Value;
44
import org.springframework.web.bind.annotation.GetMapping;
55
import org.springframework.web.bind.annotation.RestController;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
68

79
import java.util.LinkedHashMap;
810
import java.util.Map;
911

1012
@RestController
1113
public class RootController {
1214

15+
private static final Logger logger = LoggerFactory.getLogger(RootController.class);
16+
1317
@Value("${app.version}")
1418
private String version;
1519

@@ -21,6 +25,8 @@ public class RootController {
2125

2226
@GetMapping("/")
2327
public Map<String, Object> index() {
28+
logger.info("GET / - version={}, app={}, db={}", version, name, dbClient);
29+
2430
Map<String, Object> data = new LinkedHashMap<>();
2531
data.put("version", version);
2632
data.put("status", "ok");
@@ -32,5 +38,6 @@ public Map<String, Object> index() {
3238
response.put("data", data);
3339

3440
return response;
35-
}
41+
}
42+
3643
}

backend-springboot/src/main/java/com/ganatan/backend_java/modules/continent/ContinentRepositoryMock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public void loadData() {
2424
ObjectMapper mapper = new ObjectMapper();
2525
ClassPathResource resource = new ClassPathResource("data/mock/continent.json");
2626
continents = mapper.readValue(resource.getInputStream(), new TypeReference<List<Continent>>() {});
27-
System.out.println("📁 [GANATAN MOCK] JSON chargé : " + continents.size() + " continents.");
27+
System.out.println("[GANATAN MOCK] JSON chargé : " + continents.size() + " continents.");
2828
} catch (IOException e) {
29-
System.err.println("[GANATAN MOCK] Erreur JSON : " + e.getMessage());
29+
System.err.println("[GANATAN MOCK] Erreur JSON : " + e.getMessage());
3030
continents.clear();
3131
}
3232
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<configuration>
2+
3+
<property name="LOG_PATH" value="logs"/>
4+
<property name="LOG_FILE" value="${LOG_PATH}/app.log"/>
5+
6+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
7+
<file>${LOG_FILE}</file>
8+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
9+
<fileNamePattern>${LOG_PATH}/app.%d{yyyy-MM-dd}.log</fileNamePattern>
10+
<maxHistory>30</maxHistory>
11+
</rollingPolicy>
12+
<encoder>
13+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
14+
</encoder>
15+
</appender>
16+
17+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
18+
<encoder>
19+
<pattern>%cyan(%d{HH:mm:ss.SSS}) %highlight(%-5level) %magenta([%thread]) %green(%logger{20}) - %msg%n</pattern>
20+
</encoder>
21+
</appender>
22+
23+
<root level="INFO">
24+
<appender-ref ref="STDOUT"/>
25+
<appender-ref ref="FILE"/>
26+
</root>
27+
28+
</configuration>

0 commit comments

Comments
 (0)