
/**
 * 
 */
package org.tio.sitexxx.service.utils;

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

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;

public class LogUtils {
	private static Logger log = LoggerFactory.getLogger(LogUtils.class);

	private static long lastLogTime = System.currentTimeMillis();

	/**
	 * 打印jvm启动时间，大于2秒的用warn级别
	 * @param name
	 */
	public static void logJvmStartTime(String name) {
		RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
		long startTime = runtimeMxBean.getStartTime();
		long cost = System.currentTimeMillis() - lastLogTime;
		if (cost > 2000) {
			log.warn("Jvm start time:{}ms, 耗时:{}, {}", System.currentTimeMillis() - startTime, cost, name);
		} else {
			log.info("Jvm start time:{}ms, 耗时:{}, {}", System.currentTimeMillis() - startTime, cost, name);
		}

		lastLogTime = System.currentTimeMillis();
	}
}
