package com.atlassian.bitbucket.mesh.app;

import com.atlassian.bitbucket.mesh.Product;
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("Starting {} {} ({} built on {})", Product.NAME, buildInfo.getBuildVersion(),
                buildInfo.getDisplayCommitHash(), buildInfo.getBuildTimestamp());

        log.info("JVM: {} {} {}", System.getProperty("java.vm.vendor"), System.getProperty("java.vm.name"),
                System.getProperty("java.runtime.version"));
    }

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