// Path: src/main/java/de/wellnerbou/chronic/logparser/LogLineParser.java
// public interface LogLineParser {
// 
// 	LogLineData parseLine(Object logLine);
// 	String getId();
// }
// 
// Path: src/main/java/de/wellnerbou/chronic/logparser/LogLineParserProvider.java
// public class LogLineParserProvider extends ServiceLoaderImplementationProvider<LogLineParser> {
// 
// 	private String parserPattern;
// 
// 	public LogLineParserProvider(String grokPattern) {
// 		this.parserPattern = grokPattern;
// 	}
// 
// 	@Override
// 	public LogLineParser getImplementation(String id) {
// 		final LogLineParser implementation = super.getImplementation(id);
// 		if(implementation instanceof GrokLogFormatLogLineParser) {
// 			((GrokLogFormatLogLineParser) implementation).init(parserPattern, new GrokResultMapper());
// 		}
// 		return implementation;
// 	}
// 
// 	@Override
// 	protected boolean matches(final String id, final LogLineParser implementation) {
// 		return implementation.getId().equalsIgnoreCase(id);
// 	}
// 
// 	@Override
// 	protected Class<LogLineParser> getImplementationClass() {
// 		return LogLineParser.class;
// 	}
// }
// 
// Path: src/main/java/de/wellnerbou/chronic/logsource/factory/LogSourceReaderFactoryProvider.java
// public class LogSourceReaderFactoryProvider extends ServiceLoaderImplementationProvider<LogSourceReaderFactory> {
// 
// 	@Override
// 	protected boolean matches(final String id, final LogSourceReaderFactory implementation) {
// 		return implementation.getId().equalsIgnoreCase(id) || implementation.getClass().getCanonicalName().equals(id);
// 	}
// 
// 	@Override
// 	protected Class<LogSourceReaderFactory> getImplementationClass() {
// 		return LogSourceReaderFactory.class;
// 	}
// }


import com.lexicalscope.jewel.cli.ArgumentValidationException;
import com.lexicalscope.jewel.cli.Cli;
import com.lexicalscope.jewel.cli.CliFactory;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.AsyncHttpProvider;
import com.ning.http.client.providers.grizzly.GrizzlyAsyncHttpProvider;
import com.ning.http.client.providers.jdk.JDKAsyncHttpProvider;
import com.ning.http.client.providers.netty.NettyAsyncHttpProvider;
import de.wellnerbou.chronic.logparser.LogLineParser;
import de.wellnerbou.chronic.logparser.LogLineParserProvider;
import de.wellnerbou.chronic.logsource.factory.LogSourceReaderFactoryProvider;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.slf4j.MDC;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;
        if (targetserver != null) {
            MDC.put("targetserver", getLoggingDiscriminatorVariable(targetserver));
        }
    }

    static String getLoggingDiscriminatorVariable(final String hostPrefix) {
        final String targetHost = hostPrefix.replaceAll("^(ht|f)tp(s?)://", "").replace(':', '-').replace('/', '-').replaceAll("[^a-zA-Z0-9_\\-.]*", "");
        return targetHost + "_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
    }

    private InputStream getInputStreamFromGivenFile(final String file) throws IOException {
        if (new File(file).exists()) {
            return new FileInputStream(file);
        } else {
            try {
                return new URI(file).toURL().openStream();
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public void replay(final CliOptions options) throws IOException {
        final AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
        if (options.getCustomUserAgent() != null) {
            builder.setUserAgent(options.getCustomUserAgent());
        }
        builder.setAcceptAnyCertificate(options.getInsecure());
        final AsyncHttpClientConfig config = builder.build();
        try (final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(createHttpProvider(config, options))) {
// Path: src/main/java/de/wellnerbou/chronic/logparser/LogLineParser.java
// public interface LogLineParser {
// 
// 	LogLineData parseLine(Object logLine);
// 	String getId();
// }
// 
// Path: src/main/java/de/wellnerbou/chronic/logparser/LogLineParserProvider.java
// public class LogLineParserProvider extends ServiceLoaderImplementationProvider<LogLineParser> {
// 
// 	private String parserPattern;
// 
// 	public LogLineParserProvider(String grokPattern) {
// 		this.parserPattern = grokPattern;
// 	}
// 
// 	@Override
// 	public LogLineParser getImplementation(String id) {
// 		final LogLineParser implementation = super.getImplementation(id);
// 		if(implementation instanceof GrokLogFormatLogLineParser) {
// 			((GrokLogFormatLogLineParser) implementation).init(parserPattern, new GrokResultMapper());
// 		}
// 		return implementation;
// 	}
// 
// 	@Override
// 	protected boolean matches(final String id, final LogLineParser implementation) {
// 		return implementation.getId().equalsIgnoreCase(id);
// 	}
// 
// 	@Override
// 	protected Class<LogLineParser> getImplementationClass() {
// 		return LogLineParser.class;
// 	}
// }
// 
// Path: src/main/java/de/wellnerbou/chronic/logsource/factory/LogSourceReaderFactoryProvider.java
// public class LogSourceReaderFactoryProvider extends ServiceLoaderImplementationProvider<LogSourceReaderFactory> {
// 
// 	@Override
// 	protected boolean matches(final String id, final LogSourceReaderFactory implementation) {
// 		return implementation.getId().equalsIgnoreCase(id) || implementation.getClass().getCanonicalName().equals(id);
// 	}
// 
// 	@Override
// 	protected Class<LogSourceReaderFactory> getImplementationClass() {
// 		return LogSourceReaderFactory.class;
// 	}
// }


// Path: src/main/java/de/wellnerbou/chronic/replay/ChronicReplay.java
import com.lexicalscope.jewel.cli.ArgumentValidationException;
import com.lexicalscope.jewel.cli.Cli;
import com.lexicalscope.jewel.cli.CliFactory;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.AsyncHttpProvider;
import com.ning.http.client.providers.grizzly.GrizzlyAsyncHttpProvider;
import com.ning.http.client.providers.jdk.JDKAsyncHttpProvider;
import com.ning.http.client.providers.netty.NettyAsyncHttpProvider;
import de.wellnerbou.chronic.logparser.LogLineParser;
import de.wellnerbou.chronic.logparser.LogLineParserProvider;
import de.wellnerbou.chronic.logsource.factory.LogSourceReaderFactoryProvider;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.slf4j.MDC;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.Date;

        if (targetserver != null) {
            MDC.put("targetserver", getLoggingDiscriminatorVariable(targetserver));
        }
    }

    static String getLoggingDiscriminatorVariable(final String hostPrefix) {
        final String targetHost = hostPrefix.replaceAll("^(ht|f)tp(s?)://", "").replace(':', '-').replace('/', '-').replaceAll("[^a-zA-Z0-9_\\-.]*", "");
        return targetHost + "_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
    }

    private InputStream getInputStreamFromGivenFile(final String file) throws IOException {
        if (new File(file).exists()) {
            return new FileInputStream(file);
        } else {
            try {
                return new URI(file).toURL().openStream();
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public void replay(final CliOptions options) throws IOException {
        final AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
        if (options.getCustomUserAgent() != null) {
            builder.setUserAgent(options.getCustomUserAgent());
        }
        builder.setAcceptAnyCertificate(options.getInsecure());
        final AsyncHttpClientConfig config = builder.build();
        try (final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(createHttpProvider(config, options))) {
            final LogLineParserProvider logLineParserProvider = new LogLineParserProvider(options.getGrokPattern());