Skip to content

Commit

Permalink
feat: 크롤러 로깅 AOP 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed Dec 30, 2023
1 parent 38c22a0 commit ba75301
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kr.galaxyhub.sc.crawler.application

import io.github.oshai.kotlinlogging.KotlinLogging
import org.aspectj.lang.JoinPoint
import org.aspectj.lang.annotation.AfterThrowing
import org.aspectj.lang.annotation.Aspect
import org.springframework.stereotype.Component

private val log = KotlinLogging.logger {}

@Component
@Aspect
class CrawlerLogAop {

@AfterThrowing(pointcut = "this(Crawler) && execution(* crawling(String))", throwing = "ex")
fun loggingException(joinPoint: JoinPoint, ex: Exception) {
log.warn { "크롤링 중 예외가 발생했습니다. message: ${ex.message} class: ${joinPoint.target}, url: ${joinPoint.args[0]}" }
}
}
17 changes: 11 additions & 6 deletions src/main/kotlin/kr/galaxyhub/sc/crawler/config/CrawlerConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ class CrawlerConfig(
fun crawlers(): Crawlers {
return Crawlers(
listOf(
EngineeringCrawler(
objectMapper = objectMapper,
documentProvider = documentProvider(),
contentParser = markdownHtmlParser(),
introductionParser = plainHtmlParser(),
)
engineeringCrawler(),
)
)
}

@Bean
fun engineeringCrawler(): EngineeringCrawler {
return EngineeringCrawler(
objectMapper = objectMapper,
documentProvider = documentProvider(),
contentParser = markdownHtmlParser(),
introductionParser = plainHtmlParser(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.jsoup.nodes.Element
*
* 글의 내용은 g-narrative-group 태그안의 g-article 태그의 body 속성으로 나타납니다.
*/
class EngineeringCrawler(
open class EngineeringCrawler(
private val objectMapper: ObjectMapper,
private val documentProvider: DocumentProvider,
private val contentParser: HtmlParser,
Expand Down

0 comments on commit ba75301

Please sign in to comment.