Re: [D] Help with migrating from log4j to log4j2 (we also use a slf4j -> log4j) [logging-log4j2]
paladox (via GitHub) <[email protected]>
| Newsgroups | gmane.comp.jakarta.log4j.devel |
|---|---|
| Message-ID | <ghd-D_kwDOAKJSSM4AhuMF-bfb8fae1-5b60-4e4b-aa24-3d7a8f110a83__37600.7996661187$1757237108$gmane$org@gitbox.apache.org> |
GitHub user paladox added a comment to the discussion: Help with migrating from log4j to log4j2 (we also use a slf4j -> log4j)
Thanks!
For the migration, I’m focused on trying to keep most of it the same, but with the new class names and any of the function/param name changes. This is to keep it as easy as possible and to keep the same behaviour as possible to log4j 1.x.
I traced the problem back to:
```
private Log4jLogEvent log(String msg) {
SshSession sd = session.get();
CurrentUser user = sd.getUser();
StringMap ctxData = new SortedArrayStringMap();
ctxData.putValue(P_SESSION, HexFormat.fromInt(sd.getSessionId()));
String traceId = context.get().getTraceId();
if (traceId != null) ctxData.putValue(P_TRACE_ID, traceId);
String userName = "-", accountId = "-";
if (user != null && user.isIdentifiedUser()) {
IdentifiedUser u = user.asIdentifiedUser();
userName = u.getUserName().orElse("-");
accountId = "a/" + u.getAccountId().toString();
} else if (user instanceof PeerDaemonUser) {
userName = PeerDaemonUser.USER_NAME;
}
ctxData.putValue(P_USER_NAME, userName);
ctxData.putValue(P_ACCOUNT_ID, accountId);
return Log4jLogEvent.newBuilder()
.setLoggerName(SshLog.class.getName())
.setLevel(Level.INFO)
.setTimeMillis(TimeUtil.nowMs())
.setThreadName(Thread.currentThread().getName())
.setMessage(new SimpleMessage(msg))
.setContextData(ctxData)
.build();
}
```
Which I’m unsure how to fix. The problem happens only when you do ```async.append(entry);``` and only on the second time (works the first time).
GitHub link: https://github.com/apache/logging-log4j2/discussions/3914#discussioncomment-14330817
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]