Skip to content
Permalink
Browse files

rendered thread as attribute using only name

  • Loading branch information...
maciejmikosik committed Mar 27, 2018
1 parent 7147b77 commit 771a70391b5e0dcebc46f375e15c4e3963e24b13
@@ -31,12 +31,14 @@ Quick example.

prints

Thread(main) 2017-07-10T08:19:15.195Z App.start()
Thread(main) 2017-07-10T08:19:15.204Z Service#1521118594.serve()
Thread(main) 2017-07-10T08:19:15.205Z returned
Thread(main) 2017-07-10T08:19:15.205Z Service#1682463303.serve()
Thread(main) 2017-07-10T08:19:15.205Z returned
Thread(main) 2017-07-10T08:19:15.205Z returned
```
main 2018-03-27T11:57:27.493Z App.start()
main 2018-03-27T11:57:27.502Z Service#1404928347.serve()
main 2018-03-27T11:57:27.502Z returned
main 2018-03-27T11:57:27.502Z Service#949057310.serve()
main 2018-03-27T11:57:27.502Z returned
main 2018-03-27T11:57:27.503Z returned
```

Logbuddy offers possibility to generate html logs that contain images, graphs etc.

@@ -48,7 +48,7 @@

public class Documentation {
public static void main(String[] args) {
readme_html();
readme_text();
}

public static void readme_text() {
@@ -0,0 +1,34 @@
package org.logbuddy.message;

import static java.lang.String.format;
import static java.util.Objects.hash;

import java.util.Objects;

public class Attribute {
public final Object model;

private Attribute(Object model) {
this.model = model;
}

public static Attribute attribute(Object model) {
return new Attribute(model);
}

public boolean equals(Object object) {
return object instanceof Attribute && equals((Attribute) object);
}

private boolean equals(Attribute attribute) {
return Objects.equals(model, attribute.model);
}

public int hashCode() {
return hash(model);
}

public String toString() {
return format("attribute(%s)", model);
}
}
@@ -10,6 +10,7 @@
import static org.logbuddy.common.Collections.arrayToList;
import static org.logbuddy.common.Strings.times;
import static org.logbuddy.common.Throwables.stackTrace;
import static org.logbuddy.message.Attribute.attribute;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -18,6 +19,7 @@

import org.logbuddy.Message;
import org.logbuddy.Renderer;
import org.logbuddy.message.Attribute;
import org.logbuddy.message.Completed.ReturnedObject;
import org.logbuddy.message.Completed.ReturnedVoid;
import org.logbuddy.message.Completed.Thrown;
@@ -49,6 +51,8 @@ public String render(Object model) {
return renderImpl((String) model);
} else if (model instanceof Message) {
return renderImpl((Message) model);
} else if (model instanceof Attribute) {
return renderImpl((Attribute) model);
} else if (model instanceof Invoked) {
return renderImpl((Invoked) model);
} else if (model instanceof ReturnedObject) {
@@ -85,12 +89,20 @@ private String renderImpl(String string) {
private String renderImpl(Message message) {
StringBuilder builder = new StringBuilder();
for (Object attribute : message.attributes()) {
builder.append(render(attribute)).append(escape(" "));
builder.append(render(attribute(attribute))).append(escape(" "));
}
builder.append(render(message.content()));
return builder.toString();
}

private String renderImpl(Attribute attribute) {
if (attribute.model instanceof Thread) {
return render(((Thread) attribute.model).getName());
} else {
return render(attribute.model);
}
}

private String renderImpl(Invoked invoked) {
return ""
+ render(invoked.instance)
@@ -59,8 +59,8 @@ public void renders_null() {
@Test
public void renders_message() {
given(object = new Thread("content"));
given(attributeA = new Thread("attributeA"));
given(attributeB = new Thread("attributeB"));
given(attributeA = Object.class);
given(attributeB = String.class);
when(renderer.render(message(object)
.attribute(attributeA)
.attribute(attributeB)));
@@ -199,6 +199,13 @@ public void renders_thread() {
thenReturned(format("Thread(%s)", string));
}

@Test
public void renders_thread_as_attribute() {
given(thread = new Thread(string));
when(renderer.render(message(object).attribute(thread)));
thenReturned(thread.getName() + " " + renderer.render(object));
}

@Test
public void renders_class() {
given(object = Object.class);

0 comments on commit 771a703

Please sign in to comment.
You can’t perform that action at this time.