Skip to content

Commit

Permalink
[async] cleanup async handler since most of values are set by the fac…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
rmannibucau committed Nov 15, 2023
1 parent 0ec0e5d commit e32001e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public synchronized void readConfiguration() throws IOException, SecurityExcepti
}
readConfiguration(new ByteArrayInputStream(("" +
".level=INFO\n" +
".handlers=io.yupiik.logging.jul.handler.StandardHandler\n" +
".handlers=io.yupiik.logging.jul.handler.AsyncHandler\n" +
"").getBytes(StandardCharsets.UTF_8)));
}

Expand Down Expand Up @@ -371,6 +371,20 @@ private Handler createHandler(final String handlerType) {
}
}

final var filter = getProperty(handlerType + ".filter");
if (filter != null) {
try {
handler.setFilter(Thread.currentThread().getContextClassLoader()
.loadClass(filter.trim())
.asSubclass(Filter.class)
.getConstructor()
.newInstance());
} catch (final InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException | ClassNotFoundException e) {
throw new IllegalArgumentException(e);
}
}

final var level = getProperty(handlerType + ".level");
if (level != null) {
handler.setLevel(Level.parse(level));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,40 +61,6 @@ public AsyncHandler() {
throw new IllegalStateException(e);
}
}
delegate.setErrorManager(ofNullable(getErrorManager()).orElseGet(ErrorManager::new));

final var lvl = logManager.apply(className + ".level");
if (lvl != null) {
delegate.setLevel(Level.parse(lvl));
}

final var filter = logManager.apply(className + ".filter");
if (filter != null) {
try {
delegate.setFilter(AsyncHandler.class.getClassLoader().loadClass(filter).asSubclass(Filter.class).getConstructor().newInstance());
} catch (final Exception e) {
reportError(e.getMessage(), e, ErrorManager.FORMAT_FAILURE);
}
}

final var formatter = logManager.apply(className + ".formatter");
if (formatter != null) {
try {
delegate.setFormatter(AsyncHandler.class.getClassLoader().loadClass(formatter).asSubclass(Formatter.class).getConstructor().newInstance());
} catch (final Exception e) {
reportError(e.getMessage(), e, ErrorManager.FORMAT_FAILURE);
}
}
final var encoding = logManager.apply(className + ".encoding");
try {
if (encoding != null) {
delegate.setEncoding(encoding);
} else {
delegate.setEncoding(getEncoding());
}
} catch (final Exception e) {
reportError(e.getMessage(), e, ErrorManager.FORMAT_FAILURE);
}

queueSize = ofNullable(logManager.apply(className + ".queue.size"))
.map(Integer::parseInt)
Expand Down

0 comments on commit e32001e

Please # to comment.