Search in sources :

Example 1 with Logger

use of io.vertx.core.impl.logging.Logger in project vert.x by eclipse.

the class CoreExamples method example18.

public void example18(String className, Exception exception) {
    // Note -these classes are Java only
    // You would normally maintain one static instance of Logger per Java class:
    Logger logger = LoggerFactory.getLogger(className);
    logger.info("something happened");
    logger.error("oops!", exception);
}
Also used : Logger(io.vertx.core.impl.logging.Logger)

Example 2 with Logger

use of io.vertx.core.impl.logging.Logger in project vert.x by eclipse.

the class BareCommand method configureFromSystemProperties.

/**
 * This is used as workaround to retain the existing behavior of the Vert.x CLI and won't be executed
 * in other situation.
 */
public static void configureFromSystemProperties(Object options, String prefix) {
    Logger log = configureFromSystemProperties.get();
    if (log == null) {
        return;
    }
    Properties props = System.getProperties();
    Enumeration<?> e = props.propertyNames();
    // Uhh, properties suck
    while (e.hasMoreElements()) {
        String propName = (String) e.nextElement();
        String propVal = props.getProperty(propName);
        if (propName.startsWith(prefix)) {
            String fieldName = propName.substring(prefix.length());
            Method setter = getSetter(fieldName, options.getClass());
            if (setter == null) {
                log.warn("No such property to configure on options: " + options.getClass().getName() + "." + fieldName);
                continue;
            }
            Class<?> argType = setter.getParameterTypes()[0];
            Object arg;
            try {
                if (argType.equals(String.class)) {
                    arg = propVal;
                } else if (argType.equals(int.class)) {
                    arg = Integer.valueOf(propVal);
                } else if (argType.equals(long.class)) {
                    arg = Long.valueOf(propVal);
                } else if (argType.equals(boolean.class)) {
                    arg = Boolean.valueOf(propVal);
                } else if (argType.isEnum()) {
                    arg = Enum.valueOf((Class<? extends Enum>) argType, propVal);
                } else {
                    log.warn("Invalid type for setter: " + argType);
                    continue;
                }
            } catch (IllegalArgumentException e2) {
                log.warn("Invalid argtype:" + argType + " on options: " + options.getClass().getName() + "." + fieldName);
                continue;
            }
            try {
                setter.invoke(options, arg);
            } catch (Exception ex) {
                throw new VertxException("Failed to invoke setter: " + setter, ex);
            }
        }
    }
}
Also used : VertxException(io.vertx.core.VertxException) JsonObject(io.vertx.core.json.JsonObject) Method(java.lang.reflect.Method) Logger(io.vertx.core.impl.logging.Logger) Properties(java.util.Properties) VertxException(io.vertx.core.VertxException) DecodeException(io.vertx.core.json.DecodeException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Logger (io.vertx.core.impl.logging.Logger)2 VertxException (io.vertx.core.VertxException)1 DecodeException (io.vertx.core.json.DecodeException)1 JsonObject (io.vertx.core.json.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1