GitHub user paladox added a comment to the discussion: Help with migrating from
log4j to log4j2 (we also use a slf4j -> log4j)
Thanks! I came up with (for now):
```
@Inject
SshLog(
final Provider<SshSession> session,
final Provider<Context> context,
SystemLog systemLog,
@GerritServerConfig Config config,
LogConfig logConfig,
GroupAuditService auditService) {
this.session = session;
this.context = context;
this.auditService = auditService;
this.systemLog = systemLog;
this.json = logConfig.isJsonLogging();
this.text = logConfig.isTextLogging();
if (config.getBoolean("sshd", "requestLog", true)) {
enableLogging();
// This is triggered when reconfiguring e.g. in set-level running reset
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
ctx.addPropertyChangeListener(
evt -> {
if ("config".equals(evt.getPropertyName())) {
synchronized (lock) {
enableLogging();
}
}
});
}
}
/** Returns true if a change in state has occurred */
public boolean enableLogging() {
synchronized (lock) {
if (async == null || !async.isStarted()) {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration cfg = ctx.getConfiguration();
if (async != null) {
async.stop();
async = null;
}
if (text) cfg.addAppender(systemLog.createAsyncAppender(LOG_NAME, new
SshLogLayout()));
if (json)
cfg.addAppender(
systemLog.createAsyncAppender(LOG_NAME + JSON_SUFFIX, new
SshLogJsonLayout()));
List<AppenderRef> refList = new ArrayList<>();
if (text) refList.add(AppenderRef.createAppenderRef(LOG_NAME, null,
null));
if (json) refList.add(AppenderRef.createAppenderRef(LOG_NAME +
JSON_SUFFIX, null, null));
AppenderRef[] refs = refList.toArray(new AppenderRef[0]);
async =
AsyncAppender.newBuilder()
.setName("SshAsync")
.setAppenderRefs(refs)
.setConfiguration(cfg)
.build();
async.start();
cfg.addAppender(async);
ctx.updateLoggers();
return true;
}
return false;
}
}
```
For number 1 do you mean create a xml file for sshlog to define things?
Wouldn't reconfigure just get rid of that, because we use log4j2.xml?
But I'm not sure how to do the recommendations exactly.
GitHub link:
https://github.com/apache/logging-log4j2/discussions/3914#discussioncomment-14332404
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]