Skip to content

Commit

Permalink
Wallet address for Graylog originHost
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjams committed Sep 20, 2019
1 parent d772aec commit bc34af0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
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();
}
}

2 changes: 1 addition & 1 deletion src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Graylog -->
<springProperty name="graylogHost" source="graylog.host"/>
<springProperty name="graylogPort" source="graylog.port"/>
<appender name="gelf" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
<appender name="gelf" class="com.iexec.core.log.IexecGelfLogbackAppender">
<host>${graylogHost}</host>
<port>${graylogPort}</port>
</appender>
Expand Down

0 comments on commit bc34af0

Please sign in to comment.