/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.opentable.logging;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicBoolean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class CommonLogHolder
{
    private static final Logger LOG = LoggerFactory.getLogger(CommonLogHolder.class);

    private static final String UNSET = "UNSET";
    private static final AtomicBoolean WARNED_UNSET = new AtomicBoolean();

    static final DateTimeFormatter FORMAT = DateTimeFormatter.ISO_INSTANT;
    static final String HOST_NAME;
    static final Integer INSTANCE_NO;
    static final String OT_ENV, OT_ENV_TYPE, OT_ENV_LOCATION, OT_ENV_FLAVOR;
    private static String serviceType = UNSET;

    static {
        final String hostNameEnv = System.getenv("TASK_HOST");
        if (hostNameEnv != null) {
            HOST_NAME = hostNameEnv;
        } else {
            try {
                HOST_NAME = InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException e) {
                LOG.error("Failed to detect hostname", e);
                throw new ExceptionInInitializerError(e);
            }
        }
        LOG.info("Detected hostname as '{}'", HOST_NAME);

        // If not present, will be null, and not make it through buzzsaw.
        INSTANCE_NO = getInstanceNumber();
        LOG.info("Determined instance-no '{}'", INSTANCE_NO);

        OT_ENV = System.getenv("OT_ENV");
        OT_ENV_TYPE = System.getenv("OT_ENV_TYPE");
        OT_ENV_LOCATION = System.getenv("OT_ENV_LOCATION");
        OT_ENV_FLAVOR = System.getenv("OT_ENV_FLAVOR");
        LOG.info("Running in environment {} ({} {} {})", OT_ENV, OT_ENV_TYPE, OT_ENV_LOCATION, OT_ENV_FLAVOR);
    }

    private CommonLogHolder() { }

    public static void setServiceType(String serviceType) {
        CommonLogHolder.serviceType = serviceType;
    }

    public static String getServiceType() {
        if (UNSET.equals(serviceType) && WARNED_UNSET.compareAndSet(false, true)) {
            LoggerFactory.getLogger(ApplicationLogEvent.class).error("The application name was not set!  Sending 'UNSET' instead :(");
        }
        return serviceType;
    }

    private static Integer getInstanceNumber() {
        try {
            return Integer.parseInt(System.getenv("INSTANCE_NO"));
        } catch (final NumberFormatException e) {
            return null;
        }
    }
}

@@ -1206,30 +1206,24 @@
 %0A    static 
-final 
 String OT_EN
@@ -2357,24 +2357,549 @@
 lder() %7B %7D%0A%0A
+    /**%0A     * Mock out the environment.  You probably don't want to do this.%0A     */%0A    public static void setEnvironment(String otEnv, String otEnvType, String otEnvLocation, String otEnvFlavor) %7B%0A        OT_ENV = otEnv;%0A        OT_ENV_TYPE = otEnvType;%0A        OT_ENV_LOCATION = otEnvLocation;%0A        OT_ENV_FLAVOR = otEnvFlavor;%0A    %7D%0A%0A    /**%0A     * Set main %7B@code OT_ENV%7D variables to %7B@code test%7D.%0A     */%0A    public static void forceTestEnvironment() %7B%0A        setEnvironment(%22test%22, %22test%22, %22test%22, null);%0A    %7D%0A%0A
     public s

Allow mocking OT_ENV in test cases