Skip to content

Commit

Permalink
Merge pull request #334 from iExecBlockchainComputing/graylog
Browse files Browse the repository at this point in the history
Graylog
  • Loading branch information
jeremyjams authored Sep 20, 2019
2 parents 6d29c43 + bc34af0 commit b0415b1
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 12 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ dependencies {
//compile files("../iexec-common/build/libs/iexec-common-${iexecCommonVersion}.jar")

// spring
compile "org.springframework.boot:spring-boot-starter"
compile("org.springframework.boot:spring-boot-starter") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' //required for Graylog
}
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-mongodb"
compile "org.springframework.boot:spring-boot-starter-websocket"
Expand All @@ -97,6 +99,8 @@ dependencies {
// ipfs
compile "com.github.ipfs:java-ipfs-http-client:1.2.3"

//graylog
compile 'biz.paluch.logging:logstash-gelf:1.5.1'

// lombok
compileOnly "org.projectlombok:lombok:1.18.2"
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/iexec/core/log/IexecGelfLogbackAppender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.iexec.core.log;

import biz.paluch.logging.gelf.logback.GelfLogbackAppender;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.iexec.core.chain.CredentialsService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
public class IexecGelfLogbackAppender extends GelfLogbackAppender implements ApplicationContextAware {

private static String address;

public IexecGelfLogbackAppender() {
super();
}

/*
* Graylog note: The `originHost` will only contain what we want after CredentialService is loaded.
*
* Very first logs will have:
* originHost=user@user.com
* Next logs will have:
* originHost=0x12..34
*
* */
@Override
protected void append(ILoggingEvent event) {
if (address != null) {
gelfMessageAssembler.setOriginHost(address);
}
super.append(event);
}

@Override
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException {
CredentialsService credentialsService = (CredentialsService) applicationContext
.getAutowireCapableBeanFactory().getBean("credentialsService");
address = credentialsService.getCredentials().getAddress();
}
}

6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ management:
web:
exposure:
include:
- httptrace
- httptrace

graylog:
host: ${IEXEC_CORE_GRAYLOG_HOST:localhost}
port: ${IEXEC_CORE_GRAYLOG_PORT:12201}
21 changes: 21 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<!-- Default -->
<property name="LOG_LEVEL" value="${IEXEC_LOG_LEVEL:-INFO}"/>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="${LOG_LEVEL}"/>

<!-- Graylog -->
<springProperty name="graylogHost" source="graylog.host"/>
<springProperty name="graylogPort" source="graylog.port"/>
<appender name="gelf" class="com.iexec.core.log.IexecGelfLogbackAppender">
<host>${graylogHost}</host>
<port>${graylogPort}</port>
</appender>

<root level="${LOG_LEVEL}">
<appender-ref ref="gelf"/>
</root>

</configuration>
10 changes: 0 additions & 10 deletions src/main/resources/logback.xml

This file was deleted.

0 comments on commit b0415b1

Please sign in to comment.