Skip to content

Commit 640fd3b

Browse files
authored
Merge pull request #77 from Jalen-Stephens/76-implementing-logging
2 parents 84b0038 + 371faf0 commit 640fd3b

5 files changed

Lines changed: 113 additions & 1 deletion

File tree

.github/workflows/ci-reports.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: ./mvnw -B -ntp pmd:pmd -Dpmd.failOnViolation=false
4141

4242
- name: Run Checkstyle
43-
run: ./mvnw -B -ntp checkstyle:checkstyle
43+
run: ./mvnw -B -ntp checkstyle:check
4444

4545
# ===== OPTIONAL LIVE E2E (requires LIVE_E2E env + external deps) =====
4646
- name: Run live E2E (opt-in)

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ From the terminal, run the following CLI commands:
4949
mvn checkstyle:check
5050
```
5151

52+
## HTTP Request Logging
53+
All incoming HTTP requests are logged by `RequestLoggingFilter` (a Spring `OncePerRequestFilter`) using SLF4J + Logback to stdout only. Example:
54+
```
55+
2024-11-01 10:15:30.123 INFO [http-nio-8080-exec-1] dev.coms4156.project.metadetect.logging.RequestLoggingFilter - HTTP_REQUEST method=GET uri=/health query=- status=200 durationMs=12
56+
```
57+
On Heroku, view the live stream with `heroku logs --tail`.
58+
5259
## Continuous Integration & Reports
5360
---------------------------------------------------------------------
5461
- **Workflow:** `.github/workflows/ci-reports.yml` runs `./mvnw -B -ntp clean test`, `jacoco:report`, `pmd:pmd` (HTML) + `pmd:check` gate, and `checkstyle:checkstyle`. It then snapshots JaCoCo/PMD HTML to PNG via `scripts/html_to_png.sh` and uploads everything as the `ci-reports` artifact.

citations.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
### **Commit / Ticket Reference**
2+
- **Commit:** feat(logging): add request logging filter and console logback config
3+
- **Ticket:** none
4+
- **Date:** 2025-12-02
5+
- **Team Member:** Jalen Stephens
6+
7+
---
8+
9+
### **AI Tool Information**
10+
- **Tool Used:** OpenAI ChatGPT (GPT-5) via Codex CLI
11+
- **Access Method:** Local Codex CLI session (sandboxed; no paid API calls)
12+
- **Configuration:** Default model settings
13+
- **Cost:** $0 (course-provided access)
14+
15+
---
16+
17+
### **Purpose of AI Assistance**
18+
Implemented centralized HTTP request logging with SLF4J/Logback for Heroku: added a `OncePerRequestFilter` to log method/URI/status/duration, configured console-only Logback pattern, and documented usage in the README.
19+
20+
---
21+
22+
### **Prompts / Interaction Summary**
23+
- “Here’s a ready-to-paste Codex prompt you can use for your new ‘logging’ branch 👇”
24+
- “can you make a commit message and fill out a citations template for it”
25+
26+
---
27+
28+
### **Resulting Artifacts**
29+
- `src/main/java/dev/coms4156/project/metadetect/logging/RequestLoggingFilter.java`
30+
- `src/main/resources/logback-spring.xml`
31+
- `README.md`
32+
33+
---
34+
35+
### **Verification**
36+
- Not run (sandboxed session without build execution). Recommended: `./mvnw -q test`
37+
38+
---
39+
40+
### **Attribution Statement**
41+
> Portions of this work were generated with assistance from OpenAI ChatGPT (GPT-5) on 2025-12-02. All AI-generated content was reviewed and finalized by the development team.
42+
43+
---
44+
145
### **Commit / Ticket Reference**
246
- **Commit:** test: add coverage for model loader and logistic regression service
347
- **Ticket:** none
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package dev.coms4156.project.metadetect.logging;
2+
3+
import jakarta.servlet.FilterChain;
4+
import jakarta.servlet.ServletException;
5+
import jakarta.servlet.http.HttpServletRequest;
6+
import jakarta.servlet.http.HttpServletResponse;
7+
import java.io.IOException;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
import org.springframework.stereotype.Component;
11+
import org.springframework.web.filter.OncePerRequestFilter;
12+
13+
/**
14+
* Logs basic metadata for every HTTP request handled by the application.
15+
*/
16+
@Component
17+
public class RequestLoggingFilter extends OncePerRequestFilter {
18+
19+
private static final Logger log = LoggerFactory.getLogger(RequestLoggingFilter.class);
20+
21+
@Override
22+
protected void doFilterInternal(
23+
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
24+
throws ServletException, IOException {
25+
26+
long start = System.currentTimeMillis();
27+
String method = request.getMethod();
28+
String uri = request.getRequestURI();
29+
String query = request.getQueryString();
30+
31+
try {
32+
filterChain.doFilter(request, response);
33+
} finally {
34+
long durationMs = System.currentTimeMillis() - start;
35+
int status = response.getStatus();
36+
37+
log.info(
38+
"HTTP_REQUEST method={} uri={} query={} status={} durationMs={}",
39+
method,
40+
uri,
41+
query == null ? "-" : query,
42+
status,
43+
durationMs);
44+
}
45+
}
46+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<configuration>
2+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3+
<encoder>
4+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern>
5+
</encoder>
6+
</appender>
7+
8+
<!-- Tame noisy framework logs while keeping application logs at INFO -->
9+
<logger name="org.hibernate" level="WARN" />
10+
<logger name="org.springframework" level="INFO" />
11+
12+
<root level="INFO">
13+
<appender-ref ref="STDOUT" />
14+
</root>
15+
</configuration>

0 commit comments

Comments
 (0)