
io.tracee.contextlogger.builder.ConnectorFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tracee-context-logger-impl Show documentation
Show all versions of tracee-context-logger-impl Show documentation
Please refer to https://github.com/holisticon/tracee.
The newest version!
package io.tracee.contextlogger.builder;
import io.tracee.Tracee;
import io.tracee.TraceeLogger;
import io.tracee.contextlogger.Connector;
import io.tracee.contextlogger.TraceeContextLoggerConstants;
import io.tracee.contextlogger.WellKnownConnectorClassNames;
import io.tracee.contextlogger.connector.LogConnector;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Class to pipe messages to all configured connectors.
* Created by Tobias Gindler, holisticon AG on 26.03.14.
*/
public class ConnectorFactory {
// Connector settings
private static final Pattern KEY_MATCHER_PATTERN = Pattern.compile(TraceeContextLoggerConstants.SYSTEM_PROPERTY_CONTEXT_LOGGER_CONNECTOR_KEY_PATTERN);
private static final String CONNECTOR_PROPERTY_GRABBER_PATTERN =
TraceeContextLoggerConstants.SYSTEM_PROPERTY_CONNECTOR_PREFIX.replaceAll("\\.", "\\.") + "%s\\.(.*)";
private static final TraceeLogger LOGGER = Tracee.getBackend().getLoggerFactory().getLogger(TraceeContextLogger.class);
private static final Map WELL_KNOW_CONNECTOR_MAPPINGS = new HashMap();
static {
WELL_KNOW_CONNECTOR_MAPPINGS.put("HttpConnector", WellKnownConnectorClassNames.HTTP_CONNECTOR);
WELL_KNOW_CONNECTOR_MAPPINGS.put(LogConnector.class.getName(), LogConnector.class.getCanonicalName());
}
//Connector
private final Map connectorMap = new HashMap();
ConnectorFactory() {
initConnectors();
}
/**
* Initializes all available connectors.
*/
private void initConnectors() {
// first get all connector configuration Names
Set connectorConfigurationNames = this.getConnectorConfigurationNames();
for (String connectorConfigurationName : connectorConfigurationNames) {
Connector connector = this.createConnector(connectorConfigurationName);
if (connector != null) {
this.connectorMap.put(connectorConfigurationName, connector);
}
}
// Add mandatory logger
if (!isConnectorConfigured(LogConnector.class)) {
Connector logConnector = new LogConnector();
this.connectorMap.put("LOGGER", logConnector);
}
}
/**
* Send error report to all initialized connector instances.
*
* @param prefix the prefix to prepend only via the log connector output
* @param json the context data to output
*/
public final void sendErrorReportToConnectors(String prefix, String json) {
for (Connector connector : this.connectorMap.values()) {
// prevent
if (LogConnector.class.isInstance(connector)) {
connector.sendErrorReport(prefix != null ? prefix + json : json);
} else {
connector.sendErrorReport(json);
}
}
}
/**
* Extracts all names for connector configurations from System properties.
*
* @return a Set containing all connector configuration names
*/
final Set getConnectorConfigurationNames() {
Set connectorNames = new HashSet();
Enumeration
© 2015 - 2025 Weber Informatics LLC | Privacy Policy