package org.xbib.logging.integration;

import java.util.logging.LogManager;
import java.util.logging.Logger;
import org.xbib.logging.MDC;

public class SystemLoggerMain {

    public SystemLoggerMain() {
    }

    public static void main(final String[] args) {
        if (Boolean.getBoolean("system.logger.test.jul")) {
            // Access the log manager to ensure it's configured before the system property is set
            LogManager.getLogManager();
        }
        final System.Logger.Level level = System.Logger.Level.valueOf(System.getProperty("system.logger.test.level", "INFO"));
        final String msgId = System.getProperty("system.logger.test.msg.id");
        final String msg = String.format("Test message from %s id %s", SystemLoggerMain.class.getName(), msgId);
        final System.Logger systemLogger = System.getLogger(SystemLoggerMain.class.getName());
        MDC.put("logger.type", systemLogger.getClass().getName());
        MDC.put("java.util.logging.LogManager", LogManager.getLogManager().getClass().getName());
        MDC.put("java.util.logging.manager", System.getProperty("java.util.logging.manager"));
        systemLogger.log(level, msg);

        final Logger logger = Logger.getLogger(SystemLoggerMain.class.getName());
        MDC.put("logger.type", logger.getClass().getName());
        MDC.put("java.util.logging.LogManager", LogManager.getLogManager().getClass().getName());
        MDC.put("java.util.logging.manager", System.getProperty("java.util.logging.manager"));
        logger.info(msg);
    }
}