Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
[#60] Handle atomic types correctly
Browse files Browse the repository at this point in the history
atomic type arrays are now handled via an context provider.

This approach currently has a drawback.
Atomic type arrays will be outputted like this:

17:04:30.642 [main] ERROR i.t.c.connector.LogConnector - {
  "<TYPE>":"char[]",
  "value":"String<'['A', 'B', 'C', 'A', 'D', 'A', 'D', 'A', 'D', 'D', 'A', 'D', 'A', 'D', 'A', 'D', 'A', 'D', 'D', 'A', 'D', 'A', 'D', 'A']'>"
}

So we still need to add some kind of AtomicTraceeContextProvider which returns exactly one value.
  • Loading branch information
tobiasstamann committed Mar 10, 2017
1 parent 993328e commit 742f6d7
Show file tree
Hide file tree
Showing 20 changed files with 1,074 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package io.tracee.contextlogger.contextprovider.core;

import io.tracee.contextlogger.contextprovider.api.TraceeContextProviderServiceProvider;
import io.tracee.contextlogger.contextprovider.core.java.CharArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.JavaThrowableContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.BooleanArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.ByteArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.CharArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.DoubleArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.FloatArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.IntArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.LongArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.java.arrays.ShortArrayContextProvider;
import io.tracee.contextlogger.contextprovider.core.tracee.CommonDataContextProvider;
import io.tracee.contextlogger.contextprovider.core.tracee.TraceeMdcContextProvider;
import io.tracee.contextlogger.contextprovider.core.tracee.TraceeMessageContextProvider;
Expand All @@ -14,8 +21,20 @@
public class CoreContextProviderServiceProvider implements TraceeContextProviderServiceProvider {

public static final Class[] IMPLICIT_CONTEXT_PROVIDER = {CommonDataContextProvider.class, TraceeMdcContextProvider.class};
public static final Class[] CONTEXT_PROVIDER = {JavaThrowableContextProvider.class, NameValuePair.class,
TraceeMessageContextProvider.class, CharArrayContextProvider.class};
public static final Class[] CONTEXT_PROVIDER = {
JavaThrowableContextProvider.class,
NameValuePair.class,
TraceeMessageContextProvider.class,
CharArrayContextProvider.class,
ByteArrayContextProvider.class,
BooleanArrayContextProvider.class,
ShortArrayContextProvider.class,
IntArrayContextProvider.class,
LongArrayContextProvider.class,
FloatArrayContextProvider.class,
DoubleArrayContextProvider.class

};

@Override
public Class[] getImplicitContextProvider() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.tracee.contextlogger.contextprovider.core.java.arrays;


public final class ArrayContextProviderConstants {

private ArrayContextProviderConstants() {

}

protected final static String ELEMENT_SEPARATOR = ", ";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.tracee.contextlogger.contextprovider.core.java.arrays;

import io.tracee.contextlogger.contextprovider.api.ProfileConfig;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProvider;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProviderMethod;
import io.tracee.contextlogger.contextprovider.api.WrappedContextData;

@SuppressWarnings("unused")
@TraceeContextProvider(displayName = "boolean[]")
@ProfileConfig(basic = true, enhanced = true, full = true)
public class BooleanArrayContextProvider implements WrappedContextData<boolean[]> {
private boolean[] array;


@SuppressWarnings("unused")
public BooleanArrayContextProvider() {
}

@SuppressWarnings("unused")
public BooleanArrayContextProvider(final boolean[] booleanArray) {
this.array = booleanArray;
}

@Override
public void setContextData(Object instance) throws ClassCastException {
this.array = (boolean[]) instance;
}

@Override
public boolean[] getContextData() {
return this.array;
}

public Class<boolean[]> getWrappedType() {
return boolean[].class;
}

@SuppressWarnings("unused")
@TraceeContextProviderMethod(displayName = "value", order = 10)
@ProfileConfig(basic = true, enhanced = true, full = true)
public String getArrayStringRepresentation() {

if (array != null) {

StringBuilder sb = new StringBuilder();
sb.append("[");

boolean first = true;

for (boolean element : array) {
if (first) {
first = false;
} else {
sb.append(ArrayContextProviderConstants.ELEMENT_SEPARATOR);
}
sb.append(element);
}

sb.append("]");

return sb.toString();
} else {
return null;
}

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.tracee.contextlogger.contextprovider.core.java.arrays;

import io.tracee.contextlogger.contextprovider.api.ProfileConfig;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProvider;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProviderMethod;
import io.tracee.contextlogger.contextprovider.api.WrappedContextData;

import java.util.Base64;

@SuppressWarnings("unused")
@TraceeContextProvider(displayName = "byte[]")
@ProfileConfig(basic = true, enhanced = true, full = true)
public class ByteArrayContextProvider implements WrappedContextData<byte[]> {
private byte[] array;


@SuppressWarnings("unused")
public ByteArrayContextProvider() {
}

@SuppressWarnings("unused")
public ByteArrayContextProvider(final byte[] array) {
this.array = array;
}

@Override
public void setContextData(Object instance) throws ClassCastException {
this.array = (byte[]) instance;
}

@Override
public byte[] getContextData() {
return this.array;
}

public Class<byte[]> getWrappedType() {
return byte[].class;
}

@SuppressWarnings("unused")
@TraceeContextProviderMethod(displayName = "value", order = 10)
@ProfileConfig(basic = true, enhanced = true, full = true)
public String getArrayStringRepresentation() {

if (array != null) {
return Base64.getEncoder().encodeToString(array);
} else {
return null;
}

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.tracee.contextlogger.contextprovider.core.java.arrays;

import io.tracee.contextlogger.contextprovider.api.ProfileConfig;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProvider;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProviderMethod;
import io.tracee.contextlogger.contextprovider.api.WrappedContextData;

@SuppressWarnings("unused")
@TraceeContextProvider(displayName = "char[]")
@ProfileConfig(basic = true, enhanced = true, full = true)
public class CharArrayContextProvider implements WrappedContextData<char[]> {
private char[] array;


@SuppressWarnings("unused")
public CharArrayContextProvider() {
}

@SuppressWarnings("unused")
public CharArrayContextProvider(final char[] array) {
this.array = array;
}

@Override
public void setContextData(Object instance) throws ClassCastException {
this.array = (char[]) instance;
}

@Override
public char[] getContextData() {
return this.array;
}

public Class<char[]> getWrappedType() {
return char[].class;
}

@SuppressWarnings("unused")
@TraceeContextProviderMethod(displayName = "value", order = 10)
@ProfileConfig(basic = true, enhanced = true, full = true)
public String getArrayStringRepresentation() {

if (array != null) {

StringBuilder sb = new StringBuilder();
sb.append("[");

boolean first = true;

for (char element : array) {
if (first) {
first = false;
} else {
sb.append(ArrayContextProviderConstants.ELEMENT_SEPARATOR);
}
sb.append("'").append(element).append("'");
}

sb.append("]");

return sb.toString();
} else {
return null;
}

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package io.tracee.contextlogger.contextprovider.core.java.arrays;

import io.tracee.contextlogger.contextprovider.api.ProfileConfig;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProvider;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProviderMethod;
import io.tracee.contextlogger.contextprovider.api.WrappedContextData;


@SuppressWarnings("unused")
@TraceeContextProvider(displayName = "double[]")
@ProfileConfig(basic = true, enhanced = true, full = true)
public class DoubleArrayContextProvider implements WrappedContextData<double[]> {
private double[] array;


@SuppressWarnings("unused")
public DoubleArrayContextProvider() {
}

@SuppressWarnings("unused")
public DoubleArrayContextProvider(final double[] array) {
this.array = array;
}

@Override
public void setContextData(Object instance) throws ClassCastException {
this.array = (double[]) instance;
}

@Override
public double[] getContextData() {
return this.array;
}

public Class<double[]> getWrappedType() {
return double[].class;
}

@SuppressWarnings("unused")
@TraceeContextProviderMethod(displayName = "value", order = 10)
@ProfileConfig(basic = true, enhanced = true, full = true)
public String getArrayStringRepresentation() {

if (array != null) {

StringBuilder sb = new StringBuilder();
sb.append("[");

boolean first = true;

for (double element : array) {
if (first) {
first = false;
} else {
sb.append(ArrayContextProviderConstants.ELEMENT_SEPARATOR);
}
sb.append(element);
}

sb.append("]");

return sb.toString();
} else {
return null;
}

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.tracee.contextlogger.contextprovider.core.java.arrays;

import io.tracee.contextlogger.contextprovider.api.ProfileConfig;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProvider;
import io.tracee.contextlogger.contextprovider.api.TraceeContextProviderMethod;
import io.tracee.contextlogger.contextprovider.api.WrappedContextData;

@SuppressWarnings("unused")
@TraceeContextProvider(displayName = "float[]")
@ProfileConfig(basic = true, enhanced = true, full = true)
public class FloatArrayContextProvider implements WrappedContextData<float[]> {
private float[] array;


@SuppressWarnings("unused")
public FloatArrayContextProvider() {
}

@SuppressWarnings("unused")
public FloatArrayContextProvider(final float[] array) {
this.array = array;
}

@Override
public void setContextData(Object instance) throws ClassCastException {
this.array = (float[]) instance;
}

@Override
public float[] getContextData() {
return this.array;
}

public Class<float[]> getWrappedType() {
return float[].class;
}

@SuppressWarnings("unused")
@TraceeContextProviderMethod(displayName = "value", order = 10)
@ProfileConfig(basic = true, enhanced = true, full = true)
public String getArrayStringRepresentation() {

if (array != null) {

StringBuilder sb = new StringBuilder();
sb.append("[");

boolean first = true;

for (float element : array) {
if (first) {
first = false;
} else {
sb.append(ArrayContextProviderConstants.ELEMENT_SEPARATOR);
}
sb.append(element);
}

sb.append("]");

return sb.toString();
} else {
return null;
}

}


}
Loading

0 comments on commit 742f6d7

Please sign in to comment.