Skip to content

Commit

Permalink
Add separate logger for grabber
Browse files Browse the repository at this point in the history
  • Loading branch information
Pozo committed Jul 15, 2024
1 parent eedaf65 commit 6390e24
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import com.github.pozo.investmentfunds.api.grabber.processors.RedisProcessor
import org.apache.camel.LoggingLevel
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.model.dataformat.CsvDataFormat
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component

@Component
class InvestmentFundsRoutes : RouteBuilder() {

private val logger = LoggerFactory.getLogger(InvestmentFundsRoutes::class.java)

companion object {
const val FUND_DATA_ROUTE_NAME = "direct:fund-data"
const val RATE_DATA_ROUTE_NAME = "direct:rate-data"
Expand Down Expand Up @@ -43,7 +46,7 @@ class InvestmentFundsRoutes : RouteBuilder() {
"&sortDirection=dec" +
"&separator=vesszo"
)
.log(LoggingLevel.INFO, "'\${header.$ISIN_LIST_HEADER_NAME}' Downloading CSV file for the interval '\${header.$START_DATE_HEADER_NAME}'-'\${header.$END_DATE_HEADER_NAME}'")
.log(LoggingLevel.INFO, logger, "'\${header.$ISIN_LIST_HEADER_NAME}' Downloading CSV file for the interval '\${header.$START_DATE_HEADER_NAME}'-'\${header.$END_DATE_HEADER_NAME}'")
.to("https://www.bamosz.hu/bamosz-public-letoltes-portlet/data.download")
.convertBodyTo(String::class.java, "ISO-8859-2")
.convertBodyTo(String::class.java, "UTF-8")
Expand All @@ -64,7 +67,7 @@ class InvestmentFundsRoutes : RouteBuilder() {
.process(RedisProcessor.saveFundData())
//.log(LoggingLevel.INFO, "Fund data processed for '\${header.$ISIN_HEADER_NAME}'")
.doCatch(Exception::class.java)
.log(LoggingLevel.ERROR, "An error occurred during the processing : \${exception.message}")
.log(LoggingLevel.ERROR, logger, "An error occurred during the processing : \${exception.message}")
.transform().simple("\${exception.message}")
.end()

Expand All @@ -73,12 +76,12 @@ class InvestmentFundsRoutes : RouteBuilder() {
.process(RedisProcessor.saveRateData())
//.log(LoggingLevel.INFO, "Rate data processed for '\${header.$ISIN_HEADER_NAME}'")
.doCatch(Exception::class.java)
.log(LoggingLevel.ERROR, "An error occurred during the processing : \${exception.message}")
.log(LoggingLevel.ERROR, logger, "An error occurred during the processing : \${exception.message}")
.transform().simple("\${exception.message}")
.end()

from("direct:end-csv-processing").routeId("end-csv-processing")
.filter { exchange -> exchange.message.headers[START_DATE_HEADER_NAME] != null && exchange.message.headers[END_DATE_HEADER_NAME] != null }
.log("All CSV processed for (\${header.$START_DATE_HEADER_NAME}-\${header.$END_DATE_HEADER_NAME})")
.log(LoggingLevel.INFO, logger, "All CSV processed for (\${header.$START_DATE_HEADER_NAME}-\${header.$END_DATE_HEADER_NAME})")
}
}
38 changes: 38 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<configuration>
<!-- Define a file appender -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/investment-funds.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>logs/investment-funds.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- Define a console appender for general logging -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- Logger for Apache Camel -->
<logger name="org.apache.camel" level="INFO" additivity="false">
<appender-ref ref="FILE" />
</logger>
<!-- Logger for a specific class -->
<logger name="com.github.pozo.investmentfunds.api.grabber" level="INFO" additivity="false">
<appender-ref ref="FILE" />
</logger>

<!-- Disable the console appender by not including it -->

<!-- Set the root logger level to INFO and add the file appender -->
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

0 comments on commit 6390e24

Please sign in to comment.