-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
190 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ bin/ | |
.DS_Store | ||
|
||
.idea | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Filebeat Base Image | ||
FROM docker.elastic.co/beats/filebeat:8.10.0 | ||
|
||
# Copy custom Filebeat configuration | ||
COPY filebeat.yml /usr/share/filebeat/filebeat.yml | ||
|
||
# Set permissions | ||
USER root | ||
RUN chmod go-w /usr/share/filebeat/filebeat.yml | ||
|
||
# Set working directory | ||
WORKDIR /usr/share/filebeat | ||
|
||
# Entry point | ||
ENTRYPOINT ["filebeat"] | ||
CMD ["-e", "-c", "/usr/share/filebeat/filebeat.yml"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
filebeat.inputs: | ||
- type: log | ||
enabled: true | ||
paths: | ||
- ./logs/*.json | ||
json: | ||
keys_under_root: true | ||
add_error_key: true | ||
|
||
output.elasticsearch: | ||
hosts: ["192.168.0.31:9200"] | ||
username: "elastic" | ||
password: "" | ||
|
||
processors: | ||
- decode_json_fields: | ||
fields: ["message"] | ||
target: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies { | ||
implementation "co.elastic.logging:logback-ecs-encoder:${logbackEcsEncoderVersion}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencies { | ||
implementation "com.slack.api:bolt:${slackVersion}" | ||
implementation "com.slack.api:bolt-servlet:${slackVersion}" | ||
implementation "com.slack.api:bolt-jetty:${slackVersion}" | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/org/gitanimals/core/appender/SlackAppender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.gitanimals.core.appender | ||
|
||
import ch.qos.logback.classic.Level | ||
import ch.qos.logback.classic.spi.ILoggingEvent | ||
import ch.qos.logback.core.AppenderBase | ||
import com.slack.api.Slack | ||
import com.slack.api.methods.MethodsClient | ||
import com.slack.api.methods.request.chat.ChatPostMessageRequest | ||
|
||
class SlackAppender : AppenderBase<ILoggingEvent>() { | ||
|
||
lateinit var slack: MethodsClient | ||
|
||
private val errorChannel = "C080GR85WM9" | ||
private val warnChannel = "C08977RL38C" | ||
|
||
override fun append(eventObject: ILoggingEvent) { | ||
runCatching { | ||
val channel = when (eventObject.level) { | ||
Level.WARN -> warnChannel | ||
Level.ERROR -> errorChannel | ||
else -> NOT_LOGGING | ||
} | ||
|
||
if (channel == NOT_LOGGING) { | ||
return | ||
} | ||
|
||
val request: ChatPostMessageRequest = ChatPostMessageRequest.builder() | ||
.channel(channel) | ||
.text(eventObject.formattedMessage) | ||
.build(); | ||
slack.chatPostMessage(request) | ||
} | ||
} | ||
|
||
fun setToken(token: String) { | ||
this.slack = Slack.getInstance().methods(token) | ||
} | ||
|
||
companion object { | ||
private const val NOT_LOGGING = "NOT LOGGING" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
|
||
<springProperty name="LOG_LEVEL" source="logging.level.root" scope="context"/> | ||
<springProperty name="SERVICE_NAME" source="spring.application.name" scope="context"/> | ||
<springProperty name="slackToken" source="slack.token"/> | ||
<property name="LOG_PATH" value="${LOG_PATH:-./logs}"/> | ||
<property name="LOG_FILE" value="${LOG_FILE:-app}"/> | ||
<property name="LOG_PATTERN" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}][%thread] %-5level %logger{36} - %msg%n"/> | ||
<property name="MAX_HISTORY" value="${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-1}"/> | ||
|
||
<appender name="CONSOLE_APPENDER" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>${LOG_PATTERN}</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="ECS_JSON_FILE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<encoder class="co.elastic.logging.logback.EcsEncoder"> | ||
<serviceName>${SERVICE_NAME}</serviceName> | ||
</encoder> | ||
<file>${LOG_PATH}/${LOG_FILE}.json</file> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<fileNamePattern>${LOG_PATH}/${LOG_FILE}.json.%d{yyyy-MM-dd}.gz</fileNamePattern> | ||
<maxHistory>${MAX_HISTORY}</maxHistory> | ||
</rollingPolicy> | ||
</appender> | ||
<appender name = "ASYNC_ENC_JSON_FILE_APPENDER" class="ch.qos.logback.classic.AsyncAppender"> | ||
<appender-ref ref="ECS_JSON_FILE_APPENDER"/> | ||
</appender> | ||
|
||
<appender name="SLACK_APPENDER" class="org.gitanimals.core.appender.SlackAppender"> | ||
<param name="token" value="${slackToken}" /> | ||
</appender> | ||
<appender name="ASYNC_SLACK_APPENDER" class="ch.qos.logback.classic.AsyncAppender"> | ||
<appender-ref ref="SLACK_APPENDER" /> | ||
</appender> | ||
|
||
<root level="${LOG_LEVEL}"> | ||
<appender-ref ref="ASYNC_ENC_JSON_FILE_APPENDER"/> | ||
<appender-ref ref="ASYNC_SLACK_APPENDER"/> | ||
<springProfile name="test"> | ||
<appender-ref ref="CONSOLE_APPENDER"/> | ||
</springProfile> | ||
</root> | ||
|
||
</configuration> |