Skip to content

Commit

Permalink
bugfix: log messages sent as slack notifications support parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vihangpatil committed Jul 1, 2024
1 parent 8e2b6b1 commit cd6574f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ object VaultService {
)
}

private fun List<StripeService.CustomerDetails>.validate(): List<String> = buildList {
internal fun List<StripeService.CustomerDetails>.validate(): List<String> = buildList {
if (this@validate.isEmpty()) {
add("No stripe users found with this email")
} else if (this@validate.size > 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.k33.platform.app.vault

import com.k33.platform.app.vault.VaultService.validate
import com.k33.platform.app.vault.stripe.StripeService
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import java.time.LocalDate

class VaultServiceTest : StringSpec({
Expand All @@ -25,4 +28,9 @@ class VaultServiceTest : StringSpec({
mode = Mode.FETCH,
)
}
"validate user's stripe customer details" {
StripeService
.getCustomerDetails(email = "test@k33.com")
.validate() shouldBe emptyList()
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ class NotifySlackFilter : Filter<ILoggingEvent>() {
async {
SlackClient.sendRichMessage(
channel = channel,
altPlainTextMessage = header + " " + event.message,
altPlainTextMessage = header + " " + event.formattedMessage,
) {
header {
text(header, emoji = true)
}
section {
markdownText("```${event.message}```")
markdownText("```${event.formattedMessage}```")
if (mdcMap.isNotEmpty()) {
fields {
mdcMap.forEach { (key, value) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class NotifySlackFilterTest : StringSpec({
"userId" to "test-user",
"env" to "test"
) {
logger.info(NotifySlack.ALERTS, "This is information message")
logger.warn(NotifySlack.ALERTS, "This is warning message")
logger.error(NotifySlack.ALERTS, "This is error message")
logger.info(NotifySlack.ALERTS, "This is {} message", "information")
logger.warn(NotifySlack.ALERTS, "This is {} message", "warning")
logger.error(NotifySlack.ALERTS, "This is {} message", "error")
}
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>
<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>
<appender name="NOP" class="ch.qos.logback.core.helpers.NOPAppender">
<filter class="com.k33.platform.utils.logging.NotifySlackFilter" />
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="NOP"/>
</root>
</configuration>

0 comments on commit cd6574f

Please sign in to comment.