// Path: src/main/java/com/adeptj/runtime/common/LogbackManagerHolder.java
// public enum LogbackManagerHolder {
// 
//     INSTANCE;
// 
//     private LogbackManager logbackManager;
// 
//     public void setLogbackManager(LogbackManager logbackManager) {
//         if (this.logbackManager == null) {
//             this.logbackManager = logbackManager;
//         }
//     }
// 
//     public LogbackManager getLogbackManager() {
//         return this.logbackManager;
//     }
// 
//     public static LogbackManagerHolder getInstance() {
//         return INSTANCE;
//     }
// }
// 
// Path: src/main/java/com/adeptj/runtime/common/Times.java
// public final class Times {
// 
//     // No instances, just utility methods.
//     private Times() {
//     }
// 
//     /**
//      * Returns elapsed time in milliseconds from the provided time in nanoseconds.
//      *
//      * @param startTime time in nanoseconds
//      * @return elapsed time in milliseconds
//      */
//     public static long elapsedMillis(final long startTime) {
//         return NANOSECONDS.toMillis(System.nanoTime() - startTime);
//     }
// 
//     /**
//      * Returns elapsed time in seconds from the provided time in milliseconds.
//      *
//      * @param startTime time in milliseconds
//      * @return elapsed time in seconds
//      */
//     public static long elapsedSeconds(final long startTime) {
//         return MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime);
//     }
// }
// 
// Path: src/main/java/com/adeptj/runtime/config/Configs.java
// public enum Configs {
// 
//     INSTANCE;
// 
//     /**
//      * This will include system properties as well.
//      */
//     private final Config root;
// 
//     Configs() {
//         this.root = this.loadConf();
//     }
// 
//     public Config root() {
//         return this.root;
//     }
// 
//     public Config main() {
//         return this.root.getConfig(MAIN_CONF_SECTION);
//     }
// 
//     public Config undertow() {
//         return this.main().getConfig(UNDERTOW_CONF_SECTION);
//     }
// 
//     public Config felix() {
//         return this.main().getConfig(FELIX_CONF_SECTION);
//     }
// 
//     public Config common() {
//         return this.main().getConfig(COMMON_CONF_SECTION);
//     }
// 
//     public Config logging() {
//         return this.main().getConfig(LOGGING_CONF_SECTION);
//     }
// 
//     public Config trimou() {
//         return this.main().getConfig(TRIMOU_CONF_SECTION);
//     }
// 
//     public Config resteasy() {
//         return this.main().getConfig(RESTEASY_CONF_SECTION);
//     }
// 
//     private Config loadConf() {
//         Config config;
//         File configFile = Environment.getServerConfPath().toFile();
//         if (configFile.exists()) {
//             // if overwrite.server.conf.file system property is provided, then load the configs from classpath.
//             if (Boolean.getBoolean(SYS_PROP_OVERWRITE_SERVER_CONF)) {
//                 config = ConfigFactory.load(SERVER_CONF_FILE);
//             } else {
//                 config = ConfigFactory.parseFile(configFile)
//                         .withFallback(ConfigFactory.systemProperties())
//                         .resolve();
//             }
//         } else {
//             config = ConfigFactory.load(SERVER_CONF_FILE);
//         }
//         return config;
//     }
// 
//     public static Configs of() {
//         return INSTANCE;
//     }
// 
// }


import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.Configurator;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.util.StatusPrinter;
import com.adeptj.runtime.common.LogbackManagerHolder;
import com.adeptj.runtime.common.Times;
import com.adeptj.runtime.config.Configs;
import com.typesafe.config.Config;
import org.slf4j.bridge.SLF4JBridgeHandler;
/*
###############################################################################
#                                                                             # 
#    Copyright 2016, AdeptJ (http://www.adeptj.com)                           #
#                                                                             #
#    Licensed under the Apache License, Version 2.0 (the "License");          #
#    you may not use this file except in compliance with the License.         #
#    You may obtain a copy of the License at                                  #
#                                                                             #
#        http://www.apache.org/licenses/LICENSE-2.0                           #
#                                                                             #
#    Unless required by applicable law or agreed to in writing, software      #
#    distributed under the License is distributed on an "AS IS" BASIS,        #
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
#    See the License for the specific language governing permissions and      #
#    limitations under the License.                                           #
#                                                                             #
###############################################################################
*/

package com.adeptj.runtime.logging;


/**
 * This Class initializes the Logback logging framework.
 * <p>
 * Usually Logback is initialized via logback.xml file on CLASSPATH.
 * But using that approach Logback takes longer to initialize(5+ seconds) which is reduced drastically
 * to ~ 200 milliseconds using programmatic approach.
 * <p>
 * This is huge improvement on total startup time.
 *
 * @author Rakesh.Kumar, AdeptJ
 */
public final class LogbackInitializer extends ContextAwareBase implements Configurator {

    private static final String LOGBACK_INIT_MSG = "Logback initialized in [{}] ms!!";

    /**
     * See class description for details.
     *
     * @param loggerContext the {@link LoggerContext}
     */
    @Override
    public void configure(LoggerContext loggerContext) {
        long startTime = System.nanoTime();
        Config loggingCfg = Configs.of().logging();
        LogbackManager logbackManager = new LogbackManager(loggerContext);
// Path: src/main/java/com/adeptj/runtime/common/LogbackManagerHolder.java
// public enum LogbackManagerHolder {
// 
//     INSTANCE;
// 
//     private LogbackManager logbackManager;
// 
//     public void setLogbackManager(LogbackManager logbackManager) {
//         if (this.logbackManager == null) {
//             this.logbackManager = logbackManager;
//         }
//     }
// 
//     public LogbackManager getLogbackManager() {
//         return this.logbackManager;
//     }
// 
//     public static LogbackManagerHolder getInstance() {
//         return INSTANCE;
//     }
// }
// 
// Path: src/main/java/com/adeptj/runtime/common/Times.java
// public final class Times {
// 
//     // No instances, just utility methods.
//     private Times() {
//     }
// 
//     /**
//      * Returns elapsed time in milliseconds from the provided time in nanoseconds.
//      *
//      * @param startTime time in nanoseconds
//      * @return elapsed time in milliseconds
//      */
//     public static long elapsedMillis(final long startTime) {
//         return NANOSECONDS.toMillis(System.nanoTime() - startTime);
//     }
// 
//     /**
//      * Returns elapsed time in seconds from the provided time in milliseconds.
//      *
//      * @param startTime time in milliseconds
//      * @return elapsed time in seconds
//      */
//     public static long elapsedSeconds(final long startTime) {
//         return MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime);
//     }
// }
// 
// Path: src/main/java/com/adeptj/runtime/config/Configs.java
// public enum Configs {
// 
//     INSTANCE;
// 
//     /**
//      * This will include system properties as well.
//      */
//     private final Config root;
// 
//     Configs() {
//         this.root = this.loadConf();
//     }
// 
//     public Config root() {
//         return this.root;
//     }
// 
//     public Config main() {
//         return this.root.getConfig(MAIN_CONF_SECTION);
//     }
// 
//     public Config undertow() {
//         return this.main().getConfig(UNDERTOW_CONF_SECTION);
//     }
// 
//     public Config felix() {
//         return this.main().getConfig(FELIX_CONF_SECTION);
//     }
// 
//     public Config common() {
//         return this.main().getConfig(COMMON_CONF_SECTION);
//     }
// 
//     public Config logging() {
//         return this.main().getConfig(LOGGING_CONF_SECTION);
//     }
// 
//     public Config trimou() {
//         return this.main().getConfig(TRIMOU_CONF_SECTION);
//     }
// 
//     public Config resteasy() {
//         return this.main().getConfig(RESTEASY_CONF_SECTION);
//     }
// 
//     private Config loadConf() {
//         Config config;
//         File configFile = Environment.getServerConfPath().toFile();
//         if (configFile.exists()) {
//             // if overwrite.server.conf.file system property is provided, then load the configs from classpath.
//             if (Boolean.getBoolean(SYS_PROP_OVERWRITE_SERVER_CONF)) {
//                 config = ConfigFactory.load(SERVER_CONF_FILE);
//             } else {
//                 config = ConfigFactory.parseFile(configFile)
//                         .withFallback(ConfigFactory.systemProperties())
//                         .resolve();
//             }
//         } else {
//             config = ConfigFactory.load(SERVER_CONF_FILE);
//         }
//         return config;
//     }
// 
//     public static Configs of() {
//         return INSTANCE;
//     }
// 
// }


// Path: src/main/java/com/adeptj/runtime/logging/LogbackInitializer.java
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.Configurator;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.util.StatusPrinter;
import com.adeptj.runtime.common.LogbackManagerHolder;
import com.adeptj.runtime.common.Times;
import com.adeptj.runtime.config.Configs;
import com.typesafe.config.Config;
import org.slf4j.bridge.SLF4JBridgeHandler;

/*
###############################################################################
#                                                                             # 
#    Copyright 2016, AdeptJ (http://www.adeptj.com)                           #
#                                                                             #
#    Licensed under the Apache License, Version 2.0 (the "License");          #
#    you may not use this file except in compliance with the License.         #
#    You may obtain a copy of the License at                                  #
#                                                                             #
#        http://www.apache.org/licenses/LICENSE-2.0                           #
#                                                                             #
#    Unless required by applicable law or agreed to in writing, software      #
#    distributed under the License is distributed on an "AS IS" BASIS,        #
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
#    See the License for the specific language governing permissions and      #
#    limitations under the License.                                           #
#                                                                             #
###############################################################################
*/

package com.adeptj.runtime.logging;


/**
 * This Class initializes the Logback logging framework.
 * <p>
 * Usually Logback is initialized via logback.xml file on CLASSPATH.
 * But using that approach Logback takes longer to initialize(5+ seconds) which is reduced drastically
 * to ~ 200 milliseconds using programmatic approach.
 * <p>
 * This is huge improvement on total startup time.
 *
 * @author Rakesh.Kumar, AdeptJ
 */
public final class LogbackInitializer extends ContextAwareBase implements Configurator {

    private static final String LOGBACK_INIT_MSG = "Logback initialized in [{}] ms!!";

    /**
     * See class description for details.
     *
     * @param loggerContext the {@link LoggerContext}
     */
    @Override
    public void configure(LoggerContext loggerContext) {
        long startTime = System.nanoTime();
        Config loggingCfg = Configs.of().logging();
        LogbackManager logbackManager = new LogbackManager(loggerContext);
        LogbackManagerHolder.getInstance().setLogbackManager(logbackManager);