package com.atlassian.stash.internal.server;

import com.atlassian.bitbucket.Product;
import com.atlassian.stash.internal.BuildInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Logs {@link BuildInfo build information} and JVM details during system startup, to simplify determining
 * what version of the product is in use in support requests.
 */
public class BuildInfoLogger {
    
    private static final Logger log = LoggerFactory.getLogger(BuildInfoLogger.class);

    private final BuildInfo buildInfo;

    public BuildInfoLogger(BuildInfo buildInfo) {
        this.buildInfo = buildInfo;
    }
    
    public void start() {
        log.info(new StringBuilder()
                .append("Starting ")
                .append(Product.NAME)
                .append(" ")
                .append(buildInfo.getBuildVersion())
                .append(" (")
                .append(buildInfo.getDisplayCommitHash())
                .append(" built on ")
                .append(buildInfo.getBuildTimestamp())
                .append(")").toString());
        log.info(new StringBuilder()
                .append("JVM: ")
                .append(System.getProperty("java.vm.vendor"))
                .append(" ")
                .append(System.getProperty("java.vm.name"))
                .append(" ")
                .append(System.getProperty("java.runtime.version")).toString());
    }

    public void stop() {
        log.info("{} {} has shut down", Product.NAME, buildInfo.getBuildVersion());
    }
}
