Skip to content

Commit fc69e61

Browse files
committed
Add readLog method
1 parent dcb90e8 commit fc69e61

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/main/java/httpserver/Logger.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ private void createFileIfDoesntExist(Path path) {
2929
fileOperator.createFileAtPath(path);
3030
} catch (IOException e) {}
3131
}
32+
33+
public byte[] readLog() {
34+
try {
35+
return fileOperator.readContents(logPath);
36+
} catch (IOException e) {}
37+
return null;
38+
}
3239
}

src/test/java/httpserver/LoggerTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,15 @@ public void onLogCallsFileOperatorAppendWithPathAndPayload() throws Exception {
4040

4141
assertEquals("POST example\r\nHEAD example\r\n", new String(readAllBytes(logPath)));
4242
}
43+
44+
@Test
45+
public void readsLog() throws Exception {
46+
Path logPath = Paths.get(tempDir().toString(), "logs");
47+
Logger logger = new Logger(logPath, new FileOperator());
48+
49+
logger.log("POST example");
50+
logger.log("HEAD example");
51+
52+
assertEquals("POST example\r\nHEAD example\r\n", new String(logger.readLog()));
53+
}
4354
}

0 commit comments

Comments
 (0)