Skip to content

Commit 8774273

Browse files
committed
Added in ServletLogContext for the direct logger
1 parent 7e61b37 commit 8774273

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<dependency>
5252
<groupId>com.stackify</groupId>
5353
<artifactId>stackify-api</artifactId>
54-
<version>1.0.6-SNAPSHOT</version>
54+
<version>1.0.6</version>
5555
</dependency>
5656

5757
<dependency>

src/main/java/com/stackify/api/common/log/direct/LogEventAdapter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import com.stackify.api.EnvironmentDetail;
2424
import com.stackify.api.LogMsg;
2525
import com.stackify.api.StackifyError;
26+
import com.stackify.api.WebRequestDetail;
2627
import com.stackify.api.common.lang.Throwables;
2728
import com.stackify.api.common.log.EventAdapter;
29+
import com.stackify.api.common.log.ServletLogContext;
2830

2931
/**
3032
* LogEvent
@@ -68,7 +70,19 @@ public StackifyError getStackifyError(final LogEvent event, final Throwable exce
6870
} else {
6971
builder.error(Throwables.toErrorItem(event.getMessage(), event.getClassName(), event.getMethodName(), event.getLineNumber()));
7072
}
73+
74+
Optional<String> user = ServletLogContext.getUser();
75+
76+
if (user.isPresent()) {
77+
builder.userName(user.get());
78+
}
7179

80+
Optional<WebRequestDetail> webRequest = ServletLogContext.getWebRequest();
81+
82+
if (webRequest.isPresent()) {
83+
builder.webRequestDetail(webRequest.get());
84+
}
85+
7286
builder.serverVariables(Maps.fromProperties(System.getProperties()));
7387

7488
return builder.build();
@@ -87,6 +101,12 @@ public LogMsg getLogMsg(final LogEvent event, final Optional<StackifyError> erro
87101
if (event.getLevel() != null) {
88102
builder.level(event.getLevel().toLowerCase());
89103
}
104+
105+
Optional<String> transactionId = ServletLogContext.getTransactionId();
106+
107+
if (transactionId.isPresent()) {
108+
builder.transId(transactionId.get());
109+
}
90110

91111
return builder.build();
92112
}

0 commit comments

Comments
 (0)