io.github.albertus82.util.logging.AnnotationConfigHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jface-utils Show documentation
Show all versions of jface-utils Show documentation
Java SWT/JFace Utility Library including a Preferences Framework, Lightweight HTTP Server and macOS support.
package io.github.albertus82.util.logging;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import io.github.albertus82.util.logging.annotation.ExcludeLoggers;
import io.github.albertus82.util.logging.annotation.LogFormat;
public abstract class AnnotationConfigHandler extends Handler {
private final String[] exclusions;
protected AnnotationConfigHandler() {
// Exclusions
final ExcludeLoggers excludeLoggers = getClass().getAnnotation(ExcludeLoggers.class);
if (excludeLoggers != null && excludeLoggers.value() != null) {
exclusions = excludeLoggers.value();
}
else {
exclusions = new String[] {};
}
// Format
final LogFormat format = getClass().getAnnotation(LogFormat.class);
if (format != null && format.value() != null) {
setFormatter(new CustomFormatter(format.value()));
}
}
@Override
public boolean isLoggable(final LogRecord rec) {
boolean loggable = super.isLoggable(rec);
if (!loggable) {
return false;
}
else if (rec.getLoggerName() == null) {
return true;
}
else {
for (final String exclusion : exclusions) {
if (rec.getLoggerName().startsWith(exclusion)) {
return false;
}
}
return true;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy