Example usage for java.util.logging Logger log

List of usage examples for java.util.logging Logger log

Introduction

In this page you can find the example usage for java.util.logging Logger log.

Prototype

public void log(Level level, Throwable thrown, Supplier<String> msgSupplier) 

Source Link

Document

Log a lazily constructed message, with associated Throwable information.

Usage

From source file:org.protempa.backend.dsb.relationaldb.AbstractSQLGenerator.java

private static void logApplicableEntitySpecs(List<EntitySpec> allEntitySpecsCopy) {
    Logger logger = SQLGenUtil.logger();
    if (logger.isLoggable(Level.FINER)) {
        String[] allEntitySpecsCopyNames = new String[allEntitySpecsCopy.size()];
        int i = 0;
        for (EntitySpec aesc : allEntitySpecsCopy) {
            allEntitySpecsCopyNames[i++] = aesc.getName();
        }//from   ww w .j  a  va2s .co  m
        logger.log(Level.FINER, "Applicable entity specs are {0}",
                StringUtils.join(allEntitySpecsCopyNames, ", "));
    }
}

From source file:eu.trentorise.opendata.commons.test.jackson.OdtJacksonTester.java

/**
* Converts {@code obj} to an {@link ObjectNode}, sets field
* {@code fieldName} to {@code newNode} and returns the json string
* representation of such new object. Also logs the json with the provided logger at FINE
* level.// w w  w  .j  a v  a  2 s  . c om
*/
public static String changeField(ObjectMapper objectMapper, Logger logger, Object obj, String fieldName,
        JsonNode newNode) {
    checkNotNull(obj);
    checkNotEmpty(fieldName, "Invalid field name!");

    String string;
    try {
        string = objectMapper.writeValueAsString(obj);
    } catch (JsonProcessingException ex) {
        throw new RuntimeException("Error while jacksonizing object to json node!", ex);
    }
    TreeNode treeNode;
    try {
        treeNode = (ObjectNode) objectMapper.readTree(string);
    } catch (IOException ex) {
        throw new RuntimeException("Error while creating json tree from serialized object:" + string, ex);
    }
    if (!treeNode.isObject()) {
        throw new OdtException(
                "The provided object was jacksonized to a string which does not represent a JSON object! String is "
                        + string);
    }
    ObjectNode jo = (ObjectNode) treeNode;
    jo.put(fieldName, newNode);

    String json = jo.toString();

    logger.log(Level.FINE, "converted json = {0}", json);

    return json;

}

From source file:eu.trentorise.opendata.commons.test.jackson.TodJacksonTester.java

/**
 * Converts {@code obj} to an {@link ObjectNode}, sets field
 * {@code fieldName} to {@code newNode} and returns the json string
 * representation of such new object. Also logs the json with the provided
 * logger at FINE level.//ww  w. j a va 2  s. co  m
 */
public static String changeField(ObjectMapper objectMapper, Logger logger, Object obj, String fieldName,
        JsonNode newNode) {
    checkNotNull(obj);
    checkNotEmpty(fieldName, "Invalid field name!");

    String string;
    try {
        string = objectMapper.writeValueAsString(obj);
    } catch (JsonProcessingException ex) {
        throw new RuntimeException("Error while jacksonizing object to json node!", ex);
    }
    TreeNode treeNode;
    try {
        treeNode = (ObjectNode) objectMapper.readTree(string);
    } catch (IOException ex) {
        throw new RuntimeException("Error while creating json tree from serialized object:" + string, ex);
    }
    if (!treeNode.isObject()) {
        throw new TodException(
                "The provided object was jacksonized to a string which does not represent a JSON object! String is "
                        + string);
    }
    ObjectNode jo = (ObjectNode) treeNode;
    jo.put(fieldName, newNode);

    String json = jo.toString();

    logger.log(Level.FINE, "converted json = {0}", json);

    return json;

}

From source file:nl.luminis.test.util.annotations.HierarchyDiscovery.java

private void init() {
    types = new HashMap<Type, Class<?>>();
    try {//from   w w  w .  j a v a 2  s.com
        discoverTypes(type);
    } catch (StackOverflowError e) {
        Logger logger = Logger.getLogger(HierarchyDiscovery.class.getName());

        logger.log(Level.WARNING, "type: " + type.toString(), e);
        Thread.dumpStack();
        throw e;
    }
}

From source file:org.spoutcraft.launcher.entrypoint.SpoutcraftLauncher.java

protected static Logger setupLogger() {
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(Utils.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();/*from  ww  w  .j  a  v a2s  . com*/
    }
    File logs = new File(logDirectory, "techniclauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new TechnicLogFormatter());

    for (Handler h : logger.getHandlers()) {
        logger.removeHandler(h);
    }
    logger.addHandler(fileHandler);

    SpoutcraftLauncher.handler = fileHandler;

    if (params != null && !params.isDebugMode()) {
        logger.setUseParentHandlers(false);

        System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true));
        System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true));
    }

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            logger.log(Level.SEVERE, "Unhandled Exception in " + t, e);

            if (errorDialog == null) {
                LauncherFrame frame = null;

                try {
                    frame = Launcher.getFrame();
                } catch (Exception ex) {
                    //This can happen if we have a very early crash- before Launcher initializes
                }

                errorDialog = new ErrorDialog(frame, e);
                errorDialog.setVisible(true);
            }
        }
    });

    return logger;
}

From source file:org.protempa.bconfigs.ini4j.INIConfigurations.java

/**
 * Creates an INI file configurations instance that looks for configuration
 * files in the specified directory. If <code>null</code>, it first looks
 * for a system property,/*from  w  w  w.  ja v  a  2s. co m*/
 * <code>protempa.inicommonsconfigurations.pathname</code> for a pathname.
 * If unspecified, it looks for configuration files in the default location
 * (see {@link #DEFAULT_DIRECTORY}).
 *
 * @param backendProvider the provider for loading data source, knowledge
 * source, algorithm source etc. backends.
 * @param directory the directory containing backend configuration files.
 */
public INIConfigurations(BackendProvider backendProvider, File directory) {
    super(backendProvider);
    if (directory != null) {
        this.directory = directory;
    } else {
        String pathnameFromSystemProperty = System.getProperty(DIRECTORY_SYSTEM_PROPERTY);
        if (pathnameFromSystemProperty != null) {
            this.directory = new File(pathnameFromSystemProperty);
        }

    }
    if (this.directory == null) {
        this.directory = DEFAULT_DIRECTORY;
    }
    Logger logger = Ini4jUtil.logger();
    logger.log(Level.FINE, "Using configurations path {0}", this.directory);

}

From source file:edu.emory.cci.aiw.i2b2etl.dest.table.ProviderDimensionFactory.java

private Proposition resolveReference(Proposition encounterProp, String namePartReference,
        Map<UniqueId, Proposition> references) {
    Proposition provider;/*from  ww  w . j a  va2s .  co  m*/
    List<UniqueId> providerUIDs = encounterProp.getReferences(namePartReference);
    int size = providerUIDs.size();
    if (size > 0) {
        if (size > 1) {
            Logger logger = TableUtil.logger();
            logger.log(Level.WARNING, "Multiple providers found for {0}, using only the first one",
                    encounterProp);
        }
        provider = references.get(providerUIDs.get(0));
    } else {
        provider = null;
    }
    return provider;
}

From source file:org.openepics.discs.ccdb.core.dl.common.AbstractDataLoader.java

/**
 * Handles all errors that happen if the user is not authorized to perform the operation
 *
 * @param logger    Instance of logger to log the exception to server log
 * @param e         Exception that was caught in data loader implementation
 *///ww w .ja  va 2  s .c  om
protected void handleLoadingError(Logger logger, Exception e) { // NOSONAR
    logger.log(Level.FINE, e.getMessage(), e);
    if (e.getCause() instanceof org.openepics.discs.ccdb.core.security.SecurityException) {
        result.addRowMessage(ErrorMessage.NOT_AUTHORIZED, HDR_OPERATION, command);
    } else {
        result.addRowMessage(ErrorMessage.SYSTEM_EXCEPTION);
    }
}

From source file:org.openepics.discs.conf.dl.common.AbstractDataLoader.java

/**
 * Handles all errors that happen if the user is not authorized to perform the operation
 *
 * @param logger    Instance of logger to log the exception to server log
 * @param e         Exception that was caught in data loader implementation
 *//*  w w w.  ja va2  s.  c o  m*/
protected void handleLoadingError(Logger logger, Exception e) { // NOSONAR
    logger.log(Level.FINE, e.getMessage(), e);
    if (e.getCause() instanceof org.openepics.discs.conf.security.SecurityException) {
        result.addRowMessage(ErrorMessage.NOT_AUTHORIZED, HDR_OPERATION, command);
    } else {
        result.addRowMessage(ErrorMessage.SYSTEM_EXCEPTION);
    }
}

From source file:com.qwazr.server.ServerException.java

final public ServerException warnIfCause(final Logger logger) {
    final Throwable cause = getCause();
    if (cause == null)
        return this;
    if (logger != null)
        logger.log(Level.WARNING, cause, this::getMessage);
    return this;
}