Skip to content

Commit c6e4dcb

Browse files
committed
logger configured
1 parent 90ab321 commit c6e4dcb

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ out/
3838

3939
### vim ###
4040
.vim/
41+
42+
### Logs ###
43+
logs/

src/main/java/link/hiroshisprojects/kaput/authentication/AuthController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import javax.validation.Valid;
1010

1111
import org.hibernate.exception.ConstraintViolationException;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214
import org.springframework.beans.factory.annotation.Value;
1315
import org.springframework.hateoas.Link;
1416
import org.springframework.http.ResponseEntity;
@@ -38,6 +40,8 @@ public class AuthController {
3840
@Value("${admin.secret}")
3941
private String ADMIN_SECRET;
4042

43+
private Logger LOGGER = LoggerFactory.getLogger(this.getClass());
44+
4145
private UserService userService;
4246

4347
public AuthController(UserService userService) {
@@ -110,7 +114,7 @@ public ResponseEntity<Map<String, Object>> authenticate(@RequestBody Map<String,
110114
* JWT-generating filter. */
111115
@PostMapping("/api/authenticate")
112116
public void authenticate(Authentication authentication) throws UserException {
113-
// TODO add to log
117+
LOGGER.debug(String.format("Attempt to authenticate user %s", authentication.toString()));
114118
}
115119

116120
}

src/main/resources/logback-spring.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<property name="LOGS" value="./logs" />
5+
6+
<appender name="Console"
7+
class="ch.qos.logback.core.ConsoleAppender">
8+
<layout class="ch.qos.logback.classic.PatternLayout">
9+
<Pattern>
10+
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
11+
</Pattern>
12+
</layout>
13+
</appender>
14+
15+
<appender name="RollingFile"
16+
class="ch.qos.logback.core.rolling.RollingFileAppender">
17+
<file>${LOGS}/spring-boot-logger.log</file>
18+
<encoder
19+
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
20+
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
21+
</encoder>
22+
23+
<rollingPolicy
24+
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
25+
<!-- rollover daily and when the file reaches 10 MegaBytes -->
26+
<fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
27+
</fileNamePattern>
28+
<timeBasedFileNamingAndTriggeringPolicy
29+
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
30+
<maxFileSize>10MB</maxFileSize>
31+
</timeBasedFileNamingAndTriggeringPolicy>
32+
</rollingPolicy>
33+
</appender>
34+
35+
<!-- LOG everything at INFO level -->
36+
<root level="info">
37+
<appender-ref ref="RollingFile" />
38+
<appender-ref ref="Console" />
39+
</root>
40+
41+
<!-- LOG project logs at TRACE level -->
42+
<logger name="link.hiroshisprojects.kaput" level="trace" additivity="false">
43+
<appender-ref ref="RollingFile" />
44+
<appender-ref ref="Console" />
45+
</logger>
46+
47+
</configuration>

0 commit comments

Comments
 (0)