Example usage for java.util.logging Logger info

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

Introduction

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

Prototype

public void info(Supplier<String> msgSupplier) 

Source Link

Document

Log a INFO message, which is only to be constructed if the logging level is such that the message will actually be logged.

Usage

From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java

public static void write(String fName, InputData data, String outputFormat, boolean tabSeparatedClassFile,
        boolean skipInstanceNames, boolean skipInputsWithoutClass) throws IOException, SOMToolboxException {
    Logger logger = Logger.getLogger("at.tuwien.ifs.somtoolbox");
    if (outputFormat.equals(AbstractSOMLibSparseInputData.getFormatName())) {
        logger.info("Writing SOMLib Data Format.");
        InputDataWriter.writeAsSOMLib(data, data.templateVector(), data.classInformation(),
                tabSeparatedClassFile, fName + ".vec");
    } else if (outputFormat.equals(RandomAccessFileSOMLibInputData.getFormatName())) {
        logger.info("Writing Random Access Binary Data Format.");
        RandomAccessFileSOMLibInputData.write(data, fName);
    } else if (outputFormat.equals(ARFFFormatInputData.getFormatName())) {
        logger.info("Writing ARFF Data Format, skipping instance names: " + skipInstanceNames);
        InputDataWriter.writeAsWekaARFF(data, fName, !skipInstanceNames, skipInputsWithoutClass);
    } else if (outputFormat.equals(ESOMInputData.getFormatName())) {
        logger.info("Writing ESOM Data Format");
        InputDataWriter.writeAsESOM(data, fName);
    } else if (outputFormat.equals(SOMPAKInputData.getFormatName())) {
        logger.info("Writing SOMPAK Data Format");
        InputDataWriter.writeAsSOMPAK(data, fName);
    } else if (outputFormat.equals("Orange")) {
        logger.info("Writing Orange Data Format");
        InputDataWriter.writeAsOrange(data, fName);
    } else if (outputFormat.equals("CSV")) {
        logger.info("Writing CSV Format");
        InputDataWriter.writeAsCSV(data, fName);
    } else {//  w w  w.java  2s .  co  m
        // check for logical programming mistakes, basically
        throw new SOMToolboxException(
                "Didn't write format of type '" + outputFormat + "', most likely a programming error.");
    }
}

From source file:org.geoserver.jdbcconfig.internal.Util.java

/**
 * Reads SQL from the specified script and executes against a JdbcOperations instance.
 * <p>/* w  ww  . j  av a 2 s.c o  m*/
 * A few notes about the format of the file:
 * <ul>
 *   <li>Statements may span multiple lines, and must be terminated with a ";"
 *   <li>Lines starting with "--" are considered comments and ignored
 *   <li>Statements may be preceded with "?" to signal that it is ok if the statement fails  
 * </ul>
 * </p>
 */
public static void runScript(URL script, JdbcOperations jdbc, Logger logger) throws IOException {
    InputStream stream = script.openStream();
    List<String> lines;
    try {
        lines = org.apache.commons.io.IOUtils.readLines(stream);
    } finally {
        stream.close();
    }

    StringBuilder buf = new StringBuilder();
    for (String sql : lines) {
        sql = sql.trim();
        if (sql.isEmpty()) {
            continue;
        }
        if (sql.startsWith("--")) {
            continue;
        }
        buf.append(sql).append(" ");
        if (sql.endsWith(";")) {
            String stmt = buf.toString();
            boolean skipError = stmt.startsWith("?");
            if (skipError) {
                stmt = stmt.replaceAll("^\\? *", "");
            }

            if (logger != null)
                logger.info("Running: " + stmt);

            try {
                jdbc.update(stmt);
            } catch (DataAccessException e) {
                if (!skipError) {
                    throw e;
                }
            }

            buf.setLength(0);
        }
    }
}

From source file:org.openconcerto.sql.model.SQLBase.java

static public final void logCacheError(final DBItemFileCache dir, Exception e) {
    final Logger logger = Log.get();
    if (logger.isLoggable(Level.CONFIG))
        logger.log(Level.CONFIG, "invalid files in " + dir, e);
    else//w  ww. j av  a  2 s .co  m
        logger.info("invalid files in " + dir + "\n" + e.getMessage());
}

From source file:com.qwazr.search.bench.test.TestResults.java

public void log(Logger logger) {
    statsMap.forEach((clazz, stats) -> logger.info(() -> clazz + "- mean: " + (int) stats.getMean() + " - dev: "
            + (int) stats.getStandardDeviation()));
}

From source file:org.silverpeas.core.test.rule.TestStatisticRule.java

@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override//from  w ww.j  a  v a  2s.c om
        public void evaluate() throws Throwable {
            final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
            logger.info("(Thread [" + Thread.currentThread().getId() + "]) - Starting test '"
                    + description.getMethodName() + "'...");
            long start = System.currentTimeMillis();
            try {
                base.evaluate();
            } finally {
                long end = System.currentTimeMillis();
                logger.info("(Thread [" + Thread.currentThread().getId() + "]) - Test '"
                        + description.getMethodName() + "' ends, with duration of "
                        + DurationFormatUtils.formatDurationHMS(end - start));
            }
        }
    };
}

From source file:eu.wordnice.wnconsole.WNCUtils.java

protected static Thread createHIOThread(final HIOServer serv, final Handler.TwoVoidHandler<Thread, HIO> handl,
        final boolean debug, final long timeout, final Logger lg) {
    return new Thread() {
        @Override/*from  w w  w.jav a 2s  . com*/
        public void run() {
            serv.onAcceptRaw(new Handler.OneVoidHandler<Socket>() {
                @Override
                public void handle(Socket sock) {
                    try {
                        final HIO hio = new HIO(sock);
                        Thread rt = new Thread() {
                            @Override
                            public void run() {
                                try {
                                    hio.decode(false, timeout);
                                    handl.handle(this, hio);
                                } catch (Throwable th) {
                                    if (debug) {
                                        lg.info("Error while accepting client from "
                                                + hio.sock.getInetAddress().toString() + ", path [" + hio.PATH
                                                + "], error " + th.getMessage());
                                    }
                                }
                                try {
                                    hio.close();
                                } catch (Throwable tign) {
                                }
                            }
                        };
                        tid++;
                        rt.setName("WNC HIO Handle " + tid);
                        rt.start();
                    } catch (Throwable t) {
                    }
                }
            });
        }
    };
}

From source file:eu.carrade.amaury.MinecraftChatModerator.managers.core.ConfigurationBasedManager.java

/**
 * Loads the classes registered by {@link #loadAfterFollowingConfig(Class)}, if enabled in the
 * configuration file./*from ww  w  .  j a  va 2  s  . c o m*/
 *
 * <p>
 *     The configuration file format is the following.
 * </p>
 * <p>
 *     Each root-key of this configuration section must be the name of a managed class
 *     pre-registered using {@link #loadAfterFollowingConfig(Class)}, or this name without the
 *     trailing {@code suffix} (if it exists).<br />
 *     As example, with Bar? as the suffix, for the class FooBar?, the following keys will be
 *     accepted:
 *     <ul>
 *          <li>{@code FooBar} ; </li>
 *          <li>{@code Foo}.</li>
 *     </ul>
 * </p>
 * <p>
 *     The configuration sub-section? of each of these root keys can be of two different types.
 *     <ul>
 *         <li>
 *             <strong>No configuration section: a simple boolean.</strong><br />
 *             In this case, this boolean will represent the enabled? state of this filter.<br />
 *             No config will be transmitted to the subsequent managed object.<br />
 *             Example:
 *             <blockquote>
 *                 <pre>
 * FooBar: true
 *                 </pre>
 *             </blockquote>
 *         </li>
 *         <li>
 *             <strong>With a configuration section.</strong><br />
 *             The configuration section have to follow this format:
 *             <blockquote>
 *                 <pre>
 * FooBar:
 *     enabled: true  # or false
 *     options:
 *         # anything.
 *                 </pre>
 *             </blockquote>
 *             The {@code enabled} tag controls weither or not this is enabled.<br />
 *             The {@code options} configuration section represents the options passed to the
 *             constructor of the subsequent managed object (if such a constructor is present).
 *         </li>
 *     </ul>
 * </p>
 *
 * @param config The configuration section containing the whole config for this kind of managed
 *               things.
 * @param suffix The classes usual suffix removable from the class name to find the configuration
 *               key (see above).
 */
protected void load(ConfigurationSection config, String suffix) {
    final Logger logger = MinecraftChatModerator.get().getLogger();

    logger.info("Loading " + config.getName() + "...");

    for (Class<? extends MANAGED> type : toBeLoadedFromConfig) {
        final String managedName = type.getSimpleName();
        String configurationKey = managedName;

        if (!config.contains(configurationKey) && configurationKey.endsWith(suffix)) {
            configurationKey = configurationKey.substring(0, configurationKey.length() - suffix.length());
            if (!config.contains(configurationKey)) {
                logger.info(managedName + " not found in config - skipping.");
                continue;
            }
        }

        final Boolean enabled;
        final ConfigurationSection options;

        if (!config.isConfigurationSection(configurationKey)) // Simple case: managedName: true/false?.
        {
            enabled = config.getBoolean(configurationKey, false);
            options = null;
        } else // Complex case: configuration section with "enabled" and "options".
        {
            ConfigurationSection managedConfig = config.getConfigurationSection(configurationKey);

            enabled = managedConfig.getBoolean("enabled", false);
            options = managedConfig.isConfigurationSection("options")
                    ? managedConfig.getConfigurationSection("options")
                    : null;
        }

        if (!enabled)
            continue;

        MANAGED managedInstance;

        try {
            try {
                Constructor<? extends MANAGED> optionsConstructor = type
                        .getConstructor(ConfigurationSection.class);
                managedInstance = optionsConstructor.newInstance(options);
            } catch (NoSuchMethodException ignored) {
                try {
                    Constructor<? extends MANAGED> emptyConstructor = type.getConstructor();
                    managedInstance = emptyConstructor.newInstance();
                } catch (NoSuchMethodException e) {
                    logger.log(Level.SEVERE,
                            "Invalid constructor (neither with ConfigurationSection nor with nothing) in the "
                                    + managedName + " class (" + type.getName() + "), skipping.");
                    continue;
                }
            }
        } catch (InstantiationException | IllegalAccessException e) {
            logger.log(Level.SEVERE,
                    "Unable to load the " + managedName + " class (" + type.getName() + "), skipping.", e);
            continue;
        } catch (InvocationTargetException e) {
            logger.log(Level.SEVERE, "An exception occurred while loading " + managedName + ", skipping.",
                    e.getCause());
            continue;
        }

        register(managedInstance);
    }

    logger.info("Done.");
}

From source file:com.diversityarrays.kdxplore.KDXplore.java

static private java.util.logging.Logger establishLogger(ApplicationFolder appFolder) {
    // Establish logger
    java.util.logging.Logger logger = null;

    try {/*w  w w  .  ja  v a2s.co m*/
        File applicationFolder = appFolder.getApplicationFolder();

        logger = Shared.Log.getLogger();
        if (logger == null) {
            String kdxploreLog = appFolder.getApplicationName().toLowerCase() + ".log"; //$NON-NLS-1$
            File logFile = new File(applicationFolder, kdxploreLog);
            if (logFile.exists()) {
                File bakFile = new File(applicationFolder, kdxploreLog + ".bak"); //$NON-NLS-1$
                if (bakFile.exists()) {
                    bakFile.delete();
                }
                logFile.renameTo(bakFile);
            }
            java.util.logging.FileHandler fh = new FileHandler(kdxploreLog);
            fh.setFormatter(new SimpleFormatter());
            logger = java.util.logging.Logger.getLogger(appFolder.getApplicationName());
            logger.addHandler(fh);
            Shared.Log.setLogger(logger);

            logger.info("==== Log Started ===="); //$NON-NLS-1$
        }

        ExplorerProperties.getInstance(applicationFolder);
    } catch (IOException e1) {
        JOptionPane.showMessageDialog(null, e1.getMessage(), "Unable to initialise environment", //$NON-NLS-1$
                JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    return logger;
}

From source file:com.almende.eve.agent.example.ChatAgent.java

/**
 * Log a message.// w ww  .j  a  v a 2s. com
 *
 * @param message the message
 */
private void log(final String message) {
    final Logger logger = Logger.getLogger(this.getClass().getName());
    logger.info(message);
}

From source file:mockit.integration.logging.LoggingIntegrationsTest.java

@Test
public void log4jShouldLogNothing() {
    org.apache.log4j.Logger log1 = org.apache.log4j.Logger.getLogger("test");
    org.apache.log4j.Logger log2 = org.apache.log4j.Logger.getLogger(LoggingIntegrationsTest.class);
    org.apache.log4j.Logger log3 = org.apache.log4j.Logger.getLogger("test", null);
    org.apache.log4j.Logger log4 = org.apache.log4j.Logger.getRootLogger();

    assertFalse(log1.isTraceEnabled());/*from  www . ja v  a2s . c o m*/
    log1.error("testing that log4j does nothing");
    log2.setLevel(org.apache.log4j.Level.FATAL);
    log2.debug("testing that log4j does nothing");
    log3.fatal("testing that log4j does nothing");
    log4.info("testing that log4j does nothing");
}