// Path: src/main/java/net/technolords/micro/log/LogManager.java
// public class LogManager {
//     private static final Logger LOGGER = LoggerFactory.getLogger(LogManager.class);
// 
//     /**
//      * Auxiliary method to (re)initialize the logging. This method is typically called from
//      * the PropertiesManager when a external log4j2 configuration is provided, while at the
//      * same time no CLI parameter was given.
//      *
//      * Setting the new config location is enough, as it will trigger a reconfigure
//      * automatically.
//      *
//      * @param pathToLogConfiguration
//      *  A path to the external log configuration file.
//      */
//     public static void initializeLogging(String pathToLogConfiguration) {
//         Path path = FileSystems.getDefault().getPath(pathToLogConfiguration);
//         LOGGER.trace("Path to log configuration: {} -> file exists: {}", pathToLogConfiguration, Files.exists(path));
//         LoggerContext loggerContext = LoggerContext.getContext(false);
//         loggerContext.setConfigLocation(path.toUri());
//     }
// 
//     /**
//      * Auxiliary method to change the log level.
//      *
//      * @param logLevel
//      *  The log level to set.
//      *
//      * @return
//      *  A ResponseContext containing the result of the command.
//      */
//     public static ResponseContext changeLogLevel(String logLevel) {
//         ResponseContext responseContext = new ResponseContext();
//         responseContext.setContentType(ResponseContext.PLAIN_TEXT_CONTENT_TYPE);
//         LoggerContext loggerContext = LoggerContext.getContext(false);
//         Configuration configuration = loggerContext.getConfiguration();
//         LoggerConfig rootLogger = configuration.getRootLogger();
//         if (rootLogger != null) {
//             switch (StandardLevel.getStandardLevel(Level.toLevel(logLevel, Level.INFO).intLevel())) {
//                 case ERROR:
//                     rootLogger.setLevel(Level.ERROR);
//                     responseContext.setResponse("Log level changed to ERROR");
//                     break;
//                 case WARN:
//                     rootLogger.setLevel(Level.WARN);
//                     responseContext.setResponse("Log level changed to WARN");
//                     break;
//                 case INFO:
//                     rootLogger.setLevel(Level.INFO);
//                     responseContext.setResponse("Log level changed to INFO");
//                     break;
//                 case DEBUG:
//                     rootLogger.setLevel(Level.DEBUG);
//                     responseContext.setResponse("Log level changed to DEBUG");
//                     break;
//                 case OFF:
//                     rootLogger.setLevel(Level.OFF);
//                     responseContext.setResponse("Logging switched off");
//                     break;
//                 default:
//                     responseContext.setResponse("Log level unchanged, unsupported level: " + logLevel);
//             }
//             loggerContext.updateLoggers();
//         } else {
//             responseContext.setResponse("Unable to change log level, no ROOT logger found...");
//             responseContext.setErrorCode(String.valueOf(HttpURLConnection.HTTP_INTERNAL_ERROR));
//         }
//         return responseContext;
//     }
// }
// 
// Path: src/main/java/net/technolords/micro/model/ResponseContext.java
// public class ResponseContext {
//     public static final String JSON_CONTENT_TYPE = "application/json";
//     public static final String XML_CONTENT_TYPE = "application/xml";
//     public static final String PLAIN_TEXT_CONTENT_TYPE = "text/plain";
//     public static final String HTML_CONTENT_TYPE = "text/html";
//     public static final String DEFAULT_CONTENT_TYPE = JSON_CONTENT_TYPE;
//     private String response;
//     private String errorCode;
//     private String contentType = DEFAULT_CONTENT_TYPE;
// 
//     public String getResponse() {
//         return response;
//     }
// 
//     public void setResponse(String response) {
//         this.response = response;
//     }
// 
//     public String getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(String errorCode) {
//         this.errorCode = errorCode;
//     }
// 
//     public String getContentType() {
//         return contentType;
//     }
// 
//     public void setContentType(String contentType) {
//         this.contentType = contentType;
//     }
// }


import java.util.Map;
import org.apache.camel.Exchange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.technolords.micro.log.LogManager;
import net.technolords.micro.model.ResponseContext;
package net.technolords.micro.command;




public class LogCommand implements Command {
    private static final Logger LOGGER = LoggerFactory.getLogger(LogCommand.class);

    /**
     * Auxiliary method to get the id associated with this command.
     *
     * @return
     *  The id associated with the command.
     */
    @Override
    public String getId() {
        return Command.LOG;
    }

    /**
     * Auxiliary method that executes the log command. For consistency this class is kept, but in reality it
     * is delegated to the LogManager which consolidates all logic (as well as the required classes) with the
     * underlying logging framework (other than the logging facade, i.e. SLF4J).
     *
     * @param exchange
     *  The Camel Exchange associated with the log command.
     *
     * @return
     *  The result of the log command.
     */
    @Override
    public ResponseContext executeCommand(Exchange exchange) {
        Map<String, Object> commands = exchange.getIn().getHeaders();
        String logLevel = (String) commands.get(Command.LOG);
        LOGGER.debug("Log command called, with log level {}", logLevel);
// Path: src/main/java/net/technolords/micro/log/LogManager.java
// public class LogManager {
//     private static final Logger LOGGER = LoggerFactory.getLogger(LogManager.class);
// 
//     /**
//      * Auxiliary method to (re)initialize the logging. This method is typically called from
//      * the PropertiesManager when a external log4j2 configuration is provided, while at the
//      * same time no CLI parameter was given.
//      *
//      * Setting the new config location is enough, as it will trigger a reconfigure
//      * automatically.
//      *
//      * @param pathToLogConfiguration
//      *  A path to the external log configuration file.
//      */
//     public static void initializeLogging(String pathToLogConfiguration) {
//         Path path = FileSystems.getDefault().getPath(pathToLogConfiguration);
//         LOGGER.trace("Path to log configuration: {} -> file exists: {}", pathToLogConfiguration, Files.exists(path));
//         LoggerContext loggerContext = LoggerContext.getContext(false);
//         loggerContext.setConfigLocation(path.toUri());
//     }
// 
//     /**
//      * Auxiliary method to change the log level.
//      *
//      * @param logLevel
//      *  The log level to set.
//      *
//      * @return
//      *  A ResponseContext containing the result of the command.
//      */
//     public static ResponseContext changeLogLevel(String logLevel) {
//         ResponseContext responseContext = new ResponseContext();
//         responseContext.setContentType(ResponseContext.PLAIN_TEXT_CONTENT_TYPE);
//         LoggerContext loggerContext = LoggerContext.getContext(false);
//         Configuration configuration = loggerContext.getConfiguration();
//         LoggerConfig rootLogger = configuration.getRootLogger();
//         if (rootLogger != null) {
//             switch (StandardLevel.getStandardLevel(Level.toLevel(logLevel, Level.INFO).intLevel())) {
//                 case ERROR:
//                     rootLogger.setLevel(Level.ERROR);
//                     responseContext.setResponse("Log level changed to ERROR");
//                     break;
//                 case WARN:
//                     rootLogger.setLevel(Level.WARN);
//                     responseContext.setResponse("Log level changed to WARN");
//                     break;
//                 case INFO:
//                     rootLogger.setLevel(Level.INFO);
//                     responseContext.setResponse("Log level changed to INFO");
//                     break;
//                 case DEBUG:
//                     rootLogger.setLevel(Level.DEBUG);
//                     responseContext.setResponse("Log level changed to DEBUG");
//                     break;
//                 case OFF:
//                     rootLogger.setLevel(Level.OFF);
//                     responseContext.setResponse("Logging switched off");
//                     break;
//                 default:
//                     responseContext.setResponse("Log level unchanged, unsupported level: " + logLevel);
//             }
//             loggerContext.updateLoggers();
//         } else {
//             responseContext.setResponse("Unable to change log level, no ROOT logger found...");
//             responseContext.setErrorCode(String.valueOf(HttpURLConnection.HTTP_INTERNAL_ERROR));
//         }
//         return responseContext;
//     }
// }
// 
// Path: src/main/java/net/technolords/micro/model/ResponseContext.java
// public class ResponseContext {
//     public static final String JSON_CONTENT_TYPE = "application/json";
//     public static final String XML_CONTENT_TYPE = "application/xml";
//     public static final String PLAIN_TEXT_CONTENT_TYPE = "text/plain";
//     public static final String HTML_CONTENT_TYPE = "text/html";
//     public static final String DEFAULT_CONTENT_TYPE = JSON_CONTENT_TYPE;
//     private String response;
//     private String errorCode;
//     private String contentType = DEFAULT_CONTENT_TYPE;
// 
//     public String getResponse() {
//         return response;
//     }
// 
//     public void setResponse(String response) {
//         this.response = response;
//     }
// 
//     public String getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(String errorCode) {
//         this.errorCode = errorCode;
//     }
// 
//     public String getContentType() {
//         return contentType;
//     }
// 
//     public void setContentType(String contentType) {
//         this.contentType = contentType;
//     }
// }


// Path: src/main/java/net/technolords/micro/command/LogCommand.java
import java.util.Map;
import org.apache.camel.Exchange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.technolords.micro.log.LogManager;
import net.technolords.micro.model.ResponseContext;

package net.technolords.micro.command;




public class LogCommand implements Command {
    private static final Logger LOGGER = LoggerFactory.getLogger(LogCommand.class);

    /**
     * Auxiliary method to get the id associated with this command.
     *
     * @return
     *  The id associated with the command.
     */
    @Override
    public String getId() {
        return Command.LOG;
    }

    /**
     * Auxiliary method that executes the log command. For consistency this class is kept, but in reality it
     * is delegated to the LogManager which consolidates all logic (as well as the required classes) with the
     * underlying logging framework (other than the logging facade, i.e. SLF4J).
     *
     * @param exchange
     *  The Camel Exchange associated with the log command.
     *
     * @return
     *  The result of the log command.
     */
    @Override
    public ResponseContext executeCommand(Exchange exchange) {
        Map<String, Object> commands = exchange.getIn().getHeaders();
        String logLevel = (String) commands.get(Command.LOG);
        LOGGER.debug("Log command called, with log level {}", logLevel);
        return LogManager.changeLogLevel(logLevel);