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.esa.cci.sst.tools.BasicTool.java

public final ErrorHandler getErrorHandler() {
    if (errorHandler == null) {
        synchronized (this) {
            if (errorHandler == null) {
                errorHandler = new ErrorHandler() {
                    @Override/*from   w w w.  jav  a2  s .  c  o  m*/
                    public void terminate(ToolException e) {
                        final Logger localLogger = SstLogging.getLogger();
                        localLogger.log(Level.SEVERE, e.getMessage(), e);
                        if (e.getCause() != null) {
                            if (localLogger.isLoggable(Level.FINEST)) {
                                for (final StackTraceElement element : e.getCause().getStackTrace()) {
                                    localLogger.log(Level.FINEST, element.toString());
                                }
                            }
                            e.getCause().printStackTrace(System.err);
                        }
                        System.exit(e.getExitCode());
                    }

                    @Override
                    public void warn(Throwable t, String message) {
                        final Logger localLogger = SstLogging.getLogger();
                        localLogger.log(Level.WARNING, message, t);
                        if (localLogger.isLoggable(Level.FINEST)) {
                            for (final StackTraceElement element : t.getStackTrace()) {
                                localLogger.log(Level.FINEST, element.toString());
                            }
                        }
                    }
                };
            }
        }
    }
    return errorHandler;
}

From source file:org.jenkinsci.plugins.jobstreefactory.BranchAction.java

public String computeNextVersion() {
    String version = "NaN-SNAPSHOT";
    final MavenModule rootModule = getRootModule();
    if (rootModule != null && StringUtils.isNotBlank(rootModule.getVersion())) {
        try {//from  www  .jav a 2 s .  com
            DefaultVersionInfo dvi = new DefaultVersionInfo(rootModule.getVersion());
            version = dvi.getNextVersion().getSnapshotVersionString();
        } catch (Exception vpEx) {
            Logger logger = Logger.getLogger(this.getClass().getName());
            logger.log(Level.WARNING, "Failed to compute next version.", vpEx);
        }
    }
    return version;
}

From source file:org.jenkinsci.plugins.jobstreefactory.BranchAction.java

public String computeBranchVersion() {
    String version = "NaN";
    final MavenModule rootModule = getRootModule();
    if (rootModule != null && StringUtils.isNotBlank(rootModule.getVersion())) {
        try {//from  ww w  .ja va  2 s.  co m
            DefaultVersionInfo dvi = new DefaultVersionInfo(rootModule.getVersion());
            version = dvi.getReleaseVersionString();
        } catch (VersionParseException vpEx) {
            Logger logger = Logger.getLogger(this.getClass().getName());
            logger.log(Level.WARNING, "Failed to compute next version.", vpEx);
            version = rootModule.getVersion().replace("-SNAPSHOT", "");
        }
    }
    return version;
}

From source file:org.protempa.Protempa.java

/**
 * Executes a query./*from ww w.  ja  va  2s  .co m*/
 *
 * Protempa determines which propositions to retrieve from the underlying
 * data sources and compute as the union of the proposition ids specified in
 * the supplied {@link Query} and the proposition ids returned from the
 * results handler's {@link QueryResultsHandler#getPropositionIdsNeeded() }
 * method.
 *
 * @param query a {@link Query}. Cannot be <code>null</code>.
 * @param destination a destination. Cannot be <code>null</code>.
 * @throws QueryException if an error occurred during query.
 */
public void execute(Query query, Destination destination) throws QueryException {
    if (query == null) {
        throw new IllegalArgumentException("query cannot be null");
    }
    if (query.getTermIds().length > 0) {
        throw new UnsupportedOperationException("term id support has not been implemented yet.");
    }
    if (destination == null) {
        throw new IllegalArgumentException("resultsHandler cannot be null");
    }
    Logger logger = ProtempaUtil.logger();
    logger.log(Level.INFO, "Executing query {0}", query.getName());
    QuerySession qs = new QuerySession(query, this.abstractionFinder);
    this.abstractionFinder.doFind(query, destination, qs);
    logger.log(Level.INFO, "Query {0} execution complete", query.getName());
}

From source file:org.openspaces.focalserver.FocalServer.java

private void listenForRegistration() {
    Logger logger = Logger.getLogger(FocalServer.class.getName());
    try {/*from w w  w  .  ja  va  2s  .  c  om*/
        ObjectName delegateName = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        mbeanServer.addNotificationListener(delegateName, this, null, null);
    } catch (InstanceNotFoundException e1) {
        logger.log(Level.WARNING, e1.toString(), e1);
    } catch (MalformedObjectNameException e1) {
        logger.log(Level.WARNING, e1.toString(), e1);
    }
}

From source file:org.protempa.dest.xml.XmlQueryResultsHandler.java

private Element handleReferences(Set<UniqueId> handled, Map<Proposition, List<Proposition>> forwardDerivations,
        Map<Proposition, List<Proposition>> backwardDerivations, Map<UniqueId, Proposition> references,
        Proposition proposition, XmlPropositionVisitor visitor, Document document) throws ProtempaException {
    Element referencesElem = document.createElement("references");
    Collection<String> orderedReferences = orderReferences(proposition);
    Logger logger = Util.logger();
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "Ordered References for proposition {0}: {1}",
                new Object[] { proposition.getId(), orderedReferences });
    }/*from  w  w  w.j  a  v  a 2  s.  c  o  m*/
    if (orderedReferences != null) {
        for (String refName : orderedReferences) {
            logger.log(Level.FINEST, "Processing reference {0}", refName);
            List<UniqueId> uids = proposition.getReferences(refName);
            logger.log(Level.FINEST, "Total unique identifiers: {0}", uids.size());
            logger.log(Level.FINEST, "UniqueIdentifiers: {0}", uids);
            List<Proposition> refProps = createReferenceList(uids, references);
            logger.log(Level.FINEST, "Total referred propositions:  {0}", refProps.size());
            if (!refProps.isEmpty()) {
                List<Proposition> filteredReferences = filterHandled(refProps, handled);
                logger.log(Level.FINEST, "Total filtered referred propositions: {0}",
                        filteredReferences.size());
                if (!filteredReferences.isEmpty()) {
                    Element refElem = document.createElement("reference");
                    refElem.setAttribute("name", refName);
                    for (Proposition refProp : filteredReferences) {
                        Element e = handleProposition(handled, forwardDerivations, backwardDerivations,
                                references, refProp, visitor, document);
                        if (e != null) {
                            refElem.appendChild(e);
                        }
                    }
                    referencesElem.appendChild(refElem);
                } else {
                    logger.log(Level.FINEST, "Skipping reference {0} because all propositions were handled",
                            refName);
                }
            }
        }
    }
    return referencesElem;
}

From source file:org.protempa.dest.table.TableQueryResultsHandler.java

@Override
public void start(Collection<PropositionDefinition> cache) throws QueryResultsHandlerProcessingException {
    Logger logger = Util.logger();
    if (this.headerWritten) {
        try {//from w  w w.j  av  a2 s .  c o  m
            List<String> columnNames = new ArrayList<>();
            columnNames.add("KeyId");
            for (TableColumnSpec columnSpec : this.columnSpecs) {
                logger.log(Level.FINE, "Processing columnSpec type {0}", columnSpec.getClass().getName());
                String[] colNames = columnSpec.columnNames(this.knowledgeSource);
                assert colNames.length > 0 : "colNames must have length > 0";
                for (int index = 0; index < colNames.length; index++) {
                    String colName = colNames[index];
                    if (this.replace.containsKey(colName)) {
                        colNames[index] = this.replace.get(colName);
                    }
                }
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, "Got the following columns for proposition {0}: {1}", new Object[] {
                            StringUtils.join(this.rowPropositionIds, ", "), StringUtils.join(colNames, ", ") });
                }
                for (String colName : colNames) {
                    columnNames.add(colName);
                }
            }
            StringUtil.escapeAndWriteDelimitedColumns(columnNames, this.columnDelimiter, this.out);
            this.out.newLine();
        } catch (KnowledgeSourceReadException ex1) {
            throw new QueryResultsHandlerProcessingException("Error reading knowledge source", ex1);
        } catch (IOException ex) {
            throw new QueryResultsHandlerProcessingException("Could not write header", ex);
        }
    }

    try {
        this.ksCache = new KnowledgeSourceCacheFactory().getInstance(this.knowledgeSource, cache, true);
    } catch (KnowledgeSourceReadException ex) {
        throw new QueryResultsHandlerProcessingException(ex);
    }
}

From source file:org.jdesktop.wonderland.modules.service.PendingManager.java

/**
 * Adds a new module to be pending. Returns the new module object, or null
 * upon error./*  www . j a v a2  s.com*/
 */
public Module add(File jarFile) {
    /* Get the error logger */
    Logger logger = ModuleManager.getLogger();

    /* First attempt to open the URL as a module */
    Module module = null;
    try {
        module = ModuleFactory.open(jarFile);
    } catch (java.lang.Exception excp) {
        /* Log the error and return false */
        logger.log(Level.WARNING, "[MODULES] PENDING Failed to Open Module " + jarFile, excp);
        return null;
    }

    /* Next, see the module already exists, log warning and continue */
    if (this.pendingModules.containsKey(module.getName()) == true) {
        logger.log(Level.INFO, "[MODULES] PENDING Module already exists " + module.getName());
    }

    /* Add to the pending/ directory */
    File file = this.addToPending(module.getName(), jarFile);
    if (file == null) {
        logger.log(Level.WARNING, "[MODULES] PENDING Failed to add " + module.getName());
        return null;
    }

    /* Re-open the module in the new directory */
    try {
        module = ModuleFactory.open(file);

        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Add pending module " + module);
        }
    } catch (java.lang.Exception excp) {
        /* Log the error and return false */
        logger.log(Level.WARNING, "[MODULES] PENDING Failed to Open Module " + file, excp);
        return null;
    }
    /* If successful, add to the list of pending modules */
    this.pendingModules.put(module.getName(), module);
    return module;
}

From source file:net.technicpack.launcher.LauncherMain.java

private static void setupLogging(LauncherDirectories directories, ResourceLoader resources) {
    System.out.println("Setting up logging");
    final Logger logger = Utils.getLogger();
    File logDirectory = new File(directories.getLauncherDirectory(), "logs");
    if (!logDirectory.exists()) {
        logDirectory.mkdir();//ww w. jav a  2  s  . co  m
    }
    File logs = new File(logDirectory, "techniclauncher_%D.log");
    RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath());

    fileHandler.setFormatter(new BuildLogFormatter(resources.getLauncherBuild()));

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

    LauncherMain.consoleFrame = new ConsoleFrame(2500, resources.getImage("icon.png"));
    Console console = new Console(LauncherMain.consoleFrame, resources.getLauncherBuild());

    logger.addHandler(new ConsoleHandler(console));

    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) {
            e.printStackTrace();
            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);
            //                }
        }
    });
}

From source file:org.rti.zcore.dar.utils.InventoryUtils.java

public void close(Connection con, java.sql.Statement st, ResultSet rs) {

    try {/*from ww  w . j  a  v a  2 s .co m*/
        if (rs != null) {
            rs.close();
        }
        if (st != null) {
            st.close();
        }
        if (con != null) {
            con.close();
        }

    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(Version.class.getName());
        lgr.log(Level.WARNING, ex.getMessage(), ex);
    }
}