Skip to content

Commit

Permalink
Add hasException and getDumpedAt
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Apr 25, 2024
1 parent 60f827d commit 0cc8c70
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions jpos/src/main/java/org/jpos/util/LogEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class LogEvent {
private Instant dumpedAt;
private boolean honorSourceLogger;
private boolean noArmor;
private boolean hasException;

public LogEvent (String tag) {
super();
Expand Down Expand Up @@ -78,6 +79,8 @@ public void setTag (String tag) {
}
public void addMessage (Object msg) {
payLoad.add (msg);
if (msg instanceof Throwable)
hasException = true;
}
public void addMessage (String tagname, String message) {
payLoad.add ("<"+tagname+">"+message+"</"+tagname+">");
Expand All @@ -95,8 +98,7 @@ protected String dumpHeader (PrintStream p, String indent) {
if (noArmor) {
p.println("");
} else {
if (dumpedAt == null)
dumpedAt = Instant.now();
dumpedAt = getDumpedAt();
StringBuilder sb = new StringBuilder(indent);
sb.append ("<log realm=\"");
sb.append (getRealm());
Expand Down Expand Up @@ -228,6 +230,9 @@ public String toString() {
return toString("");
}

public boolean hasException() {
return hasException;
}
/**
* This is a hack for backward compatibility after accepting PR67
* @see <a href="https://github.com/jpos/jPOS/pull/67">PR67</a>
Expand All @@ -236,4 +241,13 @@ public String toString() {
public boolean isHonorSourceLogger() {
return honorSourceLogger;
}

public synchronized Instant getDumpedAt() {
if (dumpedAt == null)
dumpedAt = Instant.now();
return dumpedAt;
}
public Instant getCreatedAt() {
return createdAt;
}
}

0 comments on commit 0cc8c70

Please sign in to comment.