001package ca.uhn.hl7v2;
002
003import java.io.InputStream;
004import java.util.Properties;
005
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009/**
010 * Class to log the HAPI version when HAPI is first used (mostly for troubleshooting purposes)
011 */
012public class VersionLogger {
013
014    private static boolean ourInitialized = false;
015        private static String ourVersion;
016    private static final Logger LOG = LoggerFactory.getLogger(VersionLogger.class);
017    
018    /**
019     * Non-instantiable
020     */
021    private VersionLogger() {
022        // nothing
023    }
024    
025    /**
026     * Logs the HAPI version on the first time this method is invoked, does nothing afterwards
027     */
028    public static void init() {
029        if (!ourInitialized) {
030            try {
031                InputStream is = VersionLogger.class.getResourceAsStream("/ca/uhn/hl7v2/hapi-version.properties");
032                Properties p = new Properties();
033                p.load(is);
034                ourVersion = p.getProperty("version");
035                                LOG.info("HAPI version is: " + ourVersion);
036            } catch (Exception e) {
037                // ignore
038            }
039            ourInitialized = true;
040        }
041    }
042
043        /**
044         * @return Returns the current version of HAPI
045         */
046        public static String getVersion() {
047                return ourVersion;
048        }
049    
050}