admin管理员组文章数量:1400134
Full project on Github (check no-logs branch):
Problem: Running in docker-compose for rabbitmq and postgres. I'm not getting logs showing up for whatever reason with one exception.
I imported BezKoder's auth system and he has one class with does a logger.error
which does show:
@Component
public class AuthEntryPointJwt implements AuthenticationEntryPoint {
private static final Logger logger = LoggerFactory.getLogger(AuthEntryPointJwt.class);
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
logger.error("Unauthorized error: {}", authException.getMessage());
^ AuthEntryPointJwt in com.backend.security.jwt
I'm seeing the following entry when I trigger this error on purpose:
2025-03-24 19:49:34 2025-03-24T18:49:34.406Z ERROR 1 --- [order-taking-api] [nio-8080-exec-5] c.b.security.jwt.AuthEntryPointJwt : Unauthorized error: Full authentication is required to access this resource
If it's of any use, this is under the com.backend.security
package whereas my target logic is meant to fall under the com.backend.order
package.
I setup my OrderController in much the same way, as far as I can see:
@RestController
@RequestMapping("/api/orders")
public class OrderController {
private final static Logger log = LoggerFactory.getLogger(OrderController.class);
private final OrderService orderService;
public OrderController(OrderService orderService) {
this.orderService = orderService;
log.info("OrderController initialized");
}
@PostMapping
public ResponseEntity<String> createOrder(@RequestBody Order order) {
System.console().printf("Received order: %s%n", order);
log.info("Received order {}", order);
log.error("An error occurred while processing the order");
^ OrderController in com.backend.order.controllers
Yes lots of pointless logs but I'm seeing none of them and was wondering if it mattered whatever I changed.
The Jwt logs worked before I even did any sort of configuration straight out of the gate.
But I did include a logback-spring.xml
, updated application.properties
to log down to TRACE and define a logfile and generally followed what's mentioned here:
But alas, with all the variants I tried, the security is able to log just fine, but the other order package I built never reports anything. I'm still able to access the necessary endpoints without issue for consumption.
Setup:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOGS" value="./logs" />
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/spring-boot-logger.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<logger name="com.backend" level="trace" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
</configuration>
^ logback-spring.xml (Took from baeldun and changed the last entry from com.baeldung
to com.backend
although I have no clue if that matters)
# Logging
logging.level.root=TRACE
logging.file.name=logs/app.log
logging.file.path=logs
^ application.properties
Full project on Github (check no-logs branch): https://github/BenVella/backend-java/tree/no-logs
Problem: Running in docker-compose for rabbitmq and postgres. I'm not getting logs showing up for whatever reason with one exception.
I imported BezKoder's auth system and he has one class with does a logger.error
which does show:
@Component
public class AuthEntryPointJwt implements AuthenticationEntryPoint {
private static final Logger logger = LoggerFactory.getLogger(AuthEntryPointJwt.class);
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
logger.error("Unauthorized error: {}", authException.getMessage());
^ AuthEntryPointJwt in com.backend.security.jwt
I'm seeing the following entry when I trigger this error on purpose:
2025-03-24 19:49:34 2025-03-24T18:49:34.406Z ERROR 1 --- [order-taking-api] [nio-8080-exec-5] c.b.security.jwt.AuthEntryPointJwt : Unauthorized error: Full authentication is required to access this resource
If it's of any use, this is under the com.backend.security
package whereas my target logic is meant to fall under the com.backend.order
package.
I setup my OrderController in much the same way, as far as I can see:
@RestController
@RequestMapping("/api/orders")
public class OrderController {
private final static Logger log = LoggerFactory.getLogger(OrderController.class);
private final OrderService orderService;
public OrderController(OrderService orderService) {
this.orderService = orderService;
log.info("OrderController initialized");
}
@PostMapping
public ResponseEntity<String> createOrder(@RequestBody Order order) {
System.console().printf("Received order: %s%n", order);
log.info("Received order {}", order);
log.error("An error occurred while processing the order");
^ OrderController in com.backend.order.controllers
Yes lots of pointless logs but I'm seeing none of them and was wondering if it mattered whatever I changed.
The Jwt logs worked before I even did any sort of configuration straight out of the gate.
But I did include a logback-spring.xml
, updated application.properties
to log down to TRACE and define a logfile and generally followed what's mentioned here:
https://www.baeldung/spring-boot-logging
But alas, with all the variants I tried, the security is able to log just fine, but the other order package I built never reports anything. I'm still able to access the necessary endpoints without issue for consumption.
Setup:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOGS" value="./logs" />
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/spring-boot-logger.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>
<logger name="com.backend" level="trace" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>
</configuration>
^ logback-spring.xml (Took from baeldun and changed the last entry from com.baeldung
to com.backend
although I have no clue if that matters)
# Logging
logging.level.root=TRACE
logging.file.name=logs/app.log
logging.file.path=logs
^ application.properties
Share Improve this question asked Mar 24 at 19:14 LuponiusLuponius 992 silver badges10 bronze badges1 Answer
Reset to default 2I just ran your code in github codespaces and the logback works like charme there. So do you get the logs when executing locally but not when running in docker?
本文标签: javalogback not working the same throughout the projectStack Overflow
版权声明:本文标题:java - logback not working the same throughout the project - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744232174a2596390.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论