Skip to content

Commit

Permalink
Use loggingTag to better understand log mixing client and server.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 7, 2019
1 parent a8b8354 commit 480d886
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public LeshanClient build() {
coapConfig = createDefaultNetworkConfig();
}
if (endpointFactory == null) {
endpointFactory = new DefaultEndpointFactory() {
endpointFactory = new DefaultEndpointFactory("LWM2M Client") {
@Override
protected EndpointContextMatcher createSecuredContextMatcher() {
return null; // use default californium one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ public class DefaultEndpointFactory implements EndpointFactory {

protected EndpointContextMatcher securedContextMatcher;
protected EndpointContextMatcher unsecuredContextMatcher;
protected String loggingTag;

public DefaultEndpointFactory() {
this(null);
}

public DefaultEndpointFactory(String loggingTag) {
securedContextMatcher = createSecuredContextMatcher();
unsecuredContextMatcher = createUnsecuredContextMatcher();
if (loggingTag != null) {
this.loggingTag = loggingTag;
}
}

/**
Expand Down Expand Up @@ -82,6 +90,11 @@ protected CoapEndpoint.Builder createUnsecuredEndpointBuilder(InetSocketAddress
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setConnector(createUnsecuredConnector(address));
builder.setNetworkConfig(coapConfig);
if (loggingTag != null) {
builder.setLoggingTag("[" + loggingTag + "-coap://]");
} else {
builder.setLoggingTag("[coap://]");
}
if (unsecuredContextMatcher != null) {
builder.setEndpointContextMatcher(unsecuredContextMatcher);
}
Expand Down Expand Up @@ -118,6 +131,11 @@ protected CoapEndpoint.Builder createSecuredEndpointBuilder(DtlsConnectorConfig
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setConnector(createSecuredConnector(dtlsConfig));
builder.setNetworkConfig(coapConfig);
if (loggingTag != null) {
builder.setLoggingTag("[" + loggingTag + "-coaps://]");
} else {
builder.setLoggingTag("[coaps://]");
}
if (securedContextMatcher != null) {
builder.setEndpointContextMatcher(securedContextMatcher);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public LeshanServer build() {
if (registrationIdProvider == null)
registrationIdProvider = new RandomStringRegistrationIdProvider();
if (endpointFactory == null) {
endpointFactory = new DefaultEndpointFactory();
endpointFactory = new DefaultEndpointFactory("LWM2M Server");
}

// handle dtlsConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public BootstrapHandler create(BootstrapConfigStore store, LwM2mBootstrapRequest
coapConfig = createDefaultNetworkConfig();
}
if (endpointFactory == null) {
endpointFactory = new DefaultEndpointFactory();
endpointFactory = new DefaultEndpointFactory("LWM2M BS Server");
}
if (encoder == null)
encoder = new DefaultLwM2mNodeEncoder();
Expand Down

0 comments on commit 480d886

Please sign in to comment.