// Path: src/main/java/no/cantara/cs/config/ConstrettoConfig.java
// public class ConstrettoConfig {
// 	private static final ConstrettoConfiguration configuration = new ConstrettoBuilder()
//             .createPropertiesStore()
//             .addResource(Resource.create("classpath:application.properties"))
//             .addResource(Resource.create("file:./config_override/application_override.properties"))
//             .done()
//             .getConfiguration();
// 	
// 	private ConstrettoConfig() {}
// 	
// 	public static String getString(String key) {
// 		return configuration.evaluateToString(key);
// 	}
// 	
// 	public static Integer getInt(String key) {
// 		return configuration.evaluateToInt(key);
// 	}
// 
// 	public static Integer getInt(String key, int defaultValue) {
// 		return configuration.evaluateTo(key, defaultValue);
// 	}
// 
// 	public static boolean getBoolean(String key) {
// 		return configuration.evaluateToBoolean(key);
// 	}
// }


import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.logs.AWSLogsAsyncClient;
import com.amazonaws.services.logs.model.*;
import no.cantara.cs.config.ConstrettoConfig;
import no.cantara.cs.dto.event.EventFile;
import no.cantara.cs.dto.event.EventGroup;
import no.cantara.cs.dto.event.EventTag;
import no.cantara.cs.dto.event.ExtractedEventsStore;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
package no.cantara.cs.cloudwatch;



/**
 * Forwards log events from ConfigService clients to Amazon CloudWatch.
 * <p>
 * Assumes that the CloudWatch log groups exist, but dynamically creates log streams within the groups (one log stream
 * per client ID / tag combination).
 * <p>
 * Uses the following configuration properties:
 * <ul>
 * <li>cloudwatch.logging.enabled - Whether CloudWatch logging is enabled.</li>
 * <li>cloudwatch.region - The AWS region to use, e.g., "eu-west-1".</li>
 * <li>cloudwatch.logging.maxBatchSize - The max number of log events to bundle per AWS call. Default value: {@link #DEFAULT_MAX_BATCH_SIZE}. Must not exceed 10,000.</li>
 * <li>cloudwatch.logging.internalQueueSize - The max number of log requests to buffer internally. Default value: {@link #DEFAULT_INTERNAL_QUEUE_SIZE}.</li>
 * </ul>
 *
 * @author Sindre Mehus
 */
@Service
public class CloudWatchLogger {

    private static final Logger log = LoggerFactory.getLogger(CloudWatchLogger.class);

    private static final int DEFAULT_MAX_BATCH_SIZE = 512;
    private static final int DEFAULT_INTERNAL_QUEUE_SIZE = 1024;

    private int maxBatchSize;
    private LinkedBlockingQueue<LogRequest> logRequestQueue;
    private AWSLogsAsyncClient awsClient;

    public CloudWatchLogger() {
// Path: src/main/java/no/cantara/cs/config/ConstrettoConfig.java
// public class ConstrettoConfig {
// 	private static final ConstrettoConfiguration configuration = new ConstrettoBuilder()
//             .createPropertiesStore()
//             .addResource(Resource.create("classpath:application.properties"))
//             .addResource(Resource.create("file:./config_override/application_override.properties"))
//             .done()
//             .getConfiguration();
// 	
// 	private ConstrettoConfig() {}
// 	
// 	public static String getString(String key) {
// 		return configuration.evaluateToString(key);
// 	}
// 	
// 	public static Integer getInt(String key) {
// 		return configuration.evaluateToInt(key);
// 	}
// 
// 	public static Integer getInt(String key, int defaultValue) {
// 		return configuration.evaluateTo(key, defaultValue);
// 	}
// 
// 	public static boolean getBoolean(String key) {
// 		return configuration.evaluateToBoolean(key);
// 	}
// }


// Path: src/main/java/no/cantara/cs/cloudwatch/CloudWatchLogger.java
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.logs.AWSLogsAsyncClient;
import com.amazonaws.services.logs.model.*;
import no.cantara.cs.config.ConstrettoConfig;
import no.cantara.cs.dto.event.EventFile;
import no.cantara.cs.dto.event.EventGroup;
import no.cantara.cs.dto.event.EventTag;
import no.cantara.cs.dto.event.ExtractedEventsStore;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;

package no.cantara.cs.cloudwatch;



/**
 * Forwards log events from ConfigService clients to Amazon CloudWatch.
 * <p>
 * Assumes that the CloudWatch log groups exist, but dynamically creates log streams within the groups (one log stream
 * per client ID / tag combination).
 * <p>
 * Uses the following configuration properties:
 * <ul>
 * <li>cloudwatch.logging.enabled - Whether CloudWatch logging is enabled.</li>
 * <li>cloudwatch.region - The AWS region to use, e.g., "eu-west-1".</li>
 * <li>cloudwatch.logging.maxBatchSize - The max number of log events to bundle per AWS call. Default value: {@link #DEFAULT_MAX_BATCH_SIZE}. Must not exceed 10,000.</li>
 * <li>cloudwatch.logging.internalQueueSize - The max number of log requests to buffer internally. Default value: {@link #DEFAULT_INTERNAL_QUEUE_SIZE}.</li>
 * </ul>
 *
 * @author Sindre Mehus
 */
@Service
public class CloudWatchLogger {

    private static final Logger log = LoggerFactory.getLogger(CloudWatchLogger.class);

    private static final int DEFAULT_MAX_BATCH_SIZE = 512;
    private static final int DEFAULT_INTERNAL_QUEUE_SIZE = 1024;

    private int maxBatchSize;
    private LinkedBlockingQueue<LogRequest> logRequestQueue;
    private AWSLogsAsyncClient awsClient;

    public CloudWatchLogger() {
        if (ConstrettoConfig.getBoolean("cloudwatch.logging.enabled")) {