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, Supplier<String> msgSupplier) 

Source Link

Document

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

Usage

From source file:com.olp.jpa.domain.docu.ut.service.DeptWebServiceImpl.java

@Transactional
@Path("/test")
@POST//from   w w w  . java  2  s. c  om
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<DeptBeanPub> testPost(List<DeptBeanPub> list) throws ServiceException {

    Logger logger = Logger.getLogger(getClass().getName());
    logger.log(Level.INFO, "*** Within testPost method ***");

    return (list);
}

From source file:com.comphenix.protocol.error.DetailedErrorReporter.java

/**
 * Print the call stack to the given logger.
 * @param logger - the logger./*  ww w .j a  v a2s.c  o m*/
 */
private void printCallStack(Level level, Logger logger) {
    StringWriter text = new StringWriter();
    printCallStack(new PrintWriter(text));

    // Print the exception
    logger.log(level, text.toString());
}

From source file:org.apache.directory.studio.connection.core.io.jndi.LdifSearchLogger.java

/**
 * Logs the given text to the search logger of the given connection.
 * /*from  w ww .  ja  v  a2 s  .c  o  m*/
 * @param text the text to log
 * @param type the type, either SEARCH REQUEST or SEARCH RESULT
 * @param ex the naming exception if an error occurred, null otherwise
 * @param connection the connection
 */
private void log(String text, String type, NamingException ex, Connection connection) {
    String id = connection.getId();
    if (!loggers.containsKey(id)) {
        if (connection.getName() != null) {
            initSearchLogger(connection);
        }
    }

    if (loggers.containsKey(id)) {
        Logger logger = loggers.get(id);
        DateFormat df = new SimpleDateFormat(ConnectionCoreConstants.DATEFORMAT);
        df.setTimeZone(ConnectionCoreConstants.UTC_TIME_ZONE);

        if (ex != null) {
            logger.log(Level.ALL, LdifCommentLine.create("#!" + type + " ERROR") //$NON-NLS-1$//$NON-NLS-2$
                    .toFormattedString(LdifFormatParameters.DEFAULT));
        } else {
            logger.log(Level.ALL, LdifCommentLine.create("#!" + type + " OK") //$NON-NLS-1$//$NON-NLS-2$
                    .toFormattedString(LdifFormatParameters.DEFAULT));
        }

        logger.log(Level.ALL,
                LdifCommentLine
                        .create("#!CONNECTION ldap://" + connection.getHost() + ":" + connection.getPort()) //$NON-NLS-1$//$NON-NLS-2$
                        .toFormattedString(LdifFormatParameters.DEFAULT));
        logger.log(Level.ALL, LdifCommentLine.create("#!DATE " + df.format(new Date())) //$NON-NLS-1$
                .toFormattedString(LdifFormatParameters.DEFAULT));

        if (ex != null) {
            String errorComment = "#!ERROR " + ex.getMessage(); //$NON-NLS-1$
            errorComment = errorComment.replaceAll("\r", " "); //$NON-NLS-1$ //$NON-NLS-2$
            errorComment = errorComment.replaceAll("\n", " "); //$NON-NLS-1$ //$NON-NLS-2$
            LdifCommentLine errorCommentLine = LdifCommentLine.create(errorComment);
            logger.log(Level.ALL, errorCommentLine.toFormattedString(LdifFormatParameters.DEFAULT));
        }

        logger.log(Level.ALL, text);
    }
}

From source file:com.olp.jpa.domain.docu.ut.service.DeptWebServiceImpl.java

@Override
@Transactional/*from w w w.  ja v  a  2 s  .  c om*/
public Future<?> addAllAsync(List<DeptBeanPub> list, boolean ignoreError, Integer outputMode,
        final AsyncHandler<List<DeptBeanPub>> asyncHandler) throws ServiceException {

    Logger logger = Logger.getLogger(getClass().getName());

    logger.log(Level.INFO, "***** Within Async addAll method *****");

    final ServerAsyncResponse<List<DeptBeanPub>> r = new ServerAsyncResponse<>();

    MessageContext mContext = context.getMessageContext();
    Set<String> s = mContext.keySet();
    Iterator<String> iter = s == null ? null : s.iterator();
    while (iter != null && iter.hasNext()) {
        logger.log(Level.INFO, "MessageContext property - {0}", iter.next());
    }

    WrappedMessageContext wmc = (WrappedMessageContext) mContext;
    Message m = wmc.getWrappedMessage();

    Set<String> s2 = m.keySet();
    Iterator<String> iter2 = s2 == null ? null : s2.iterator();
    while (iter2 != null && iter2.hasNext()) {
        logger.log(Level.INFO, "Message property - {0}", iter2.next());
    }

    AddressingProperties addressProp = (AddressingProperties) mContext
            .get(org.apache.cxf.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND);

    EndpointReferenceType eprType = addressProp.getReplyTo();

    return (r);
}

From source file:com.olp.jpa.domain.docu.ut.service.DeptWebServiceImpl.java

@Override
@UseAsyncMethod// ww w.  j  ava 2  s.c  o m
@Transactional
@Path("/bulk")
@POST
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<DeptBeanPub> addAll(List<DeptBeanPub> list,
        @DefaultValue("false") @QueryParam("ignoreError") boolean ignoreError,
        @DefaultValue("0") @QueryParam("outputMode") Integer outputMode) throws ServiceException {

    Logger logger = Logger.getLogger(getClass().getName());

    logger.log(Level.INFO, "******** addAll Sync method called *********");

    if (list == null || list.size() < 1) {
        ServiceException se = FaultUtil.makeServiceException("Null department parameter received",
                new IllegalArgumentException("Null department parameter received"));
        throw se;
    }

    //if (ignoreError) {
    for (int i = 0; i < list.size(); i++) {
        DeptBeanPub bean = list.get(i);

        try {
            DepartmentBean bean2 = bean.convertTo(0);
            service.add(bean2);
            bean.setId(bean2.getId());
            bean.setRevisionControl(bean2.getRevisionControl());
        } catch (Throwable t) {
            if (ignoreError) {
                Logger.getLogger(getClass().getName()).log(Level.SEVERE,
                        "Exception encountered while adding department with code " + bean.getDeptCode(), t);
            } else {
                ServiceException se = FaultUtil.makeServiceException(
                        "Exception occurred in addAllDept service for department code " + bean.getDeptCode(),
                        t);
                throw se;
            }
        }

    }
    //}

    return (list);
}

From source file:org.torproject.ernie.db.ArchiveReader.java

public ArchiveReader(RelayDescriptorParser rdp, String archivesDir, boolean keepImportHistory) {
    int parsedFiles = 0, ignoredFiles = 0;
    Logger logger = Logger.getLogger(ArchiveReader.class.getName());
    SortedSet<String> archivesImportHistory = new TreeSet<String>();
    File archivesImportHistoryFile = new File("stats/archives-import-history");
    if (keepImportHistory && archivesImportHistoryFile.exists()) {
        try {//  w ww.  jav  a 2 s  .  c o  m
            BufferedReader br = new BufferedReader(new FileReader(archivesImportHistoryFile));
            String line = null;
            while ((line = br.readLine()) != null) {
                archivesImportHistory.add(line);
            }
            br.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "Could not read in archives import " + "history file. Skipping.");
        }
    }
    if (new File(archivesDir).exists()) {
        logger.fine("Importing files in directory " + archivesDir + "/...");
        Stack<File> filesInInputDir = new Stack<File>();
        filesInInputDir.add(new File(archivesDir));
        List<File> problems = new ArrayList<File>();
        while (!filesInInputDir.isEmpty()) {
            File pop = filesInInputDir.pop();
            if (pop.isDirectory()) {
                for (File f : pop.listFiles()) {
                    filesInInputDir.add(f);
                }
            } else {
                if (rdp != null) {
                    try {
                        BufferedInputStream bis = null;
                        if (keepImportHistory && archivesImportHistory.contains(pop.getName())) {
                            ignoredFiles++;
                            continue;
                        } else if (pop.getName().endsWith(".tar.bz2")) {
                            logger.warning(
                                    "Cannot parse compressed tarball " + pop.getAbsolutePath() + ". Skipping.");
                            continue;
                        } else if (pop.getName().endsWith(".bz2")) {
                            FileInputStream fis = new FileInputStream(pop);
                            BZip2CompressorInputStream bcis = new BZip2CompressorInputStream(fis);
                            bis = new BufferedInputStream(bcis);
                        } else {
                            FileInputStream fis = new FileInputStream(pop);
                            bis = new BufferedInputStream(fis);
                        }
                        if (keepImportHistory) {
                            archivesImportHistory.add(pop.getName());
                        }
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        int len;
                        byte[] data = new byte[1024];
                        while ((len = bis.read(data, 0, 1024)) >= 0) {
                            baos.write(data, 0, len);
                        }
                        bis.close();
                        byte[] allData = baos.toByteArray();
                        rdp.parse(allData);
                        parsedFiles++;
                    } catch (IOException e) {
                        problems.add(pop);
                        if (problems.size() > 3) {
                            break;
                        }
                    }
                }
            }
        }
        if (problems.isEmpty()) {
            logger.fine("Finished importing files in directory " + archivesDir + "/.");
        } else {
            StringBuilder sb = new StringBuilder(
                    "Failed importing files in " + "directory " + archivesDir + "/:");
            int printed = 0;
            for (File f : problems) {
                sb.append("\n  " + f.getAbsolutePath());
                if (++printed >= 3) {
                    sb.append("\n  ... more");
                    break;
                }
            }
        }
    }
    if (keepImportHistory) {
        try {
            archivesImportHistoryFile.getParentFile().mkdirs();
            BufferedWriter bw = new BufferedWriter(new FileWriter(archivesImportHistoryFile));
            for (String line : archivesImportHistory) {
                bw.write(line + "\n");
            }
            bw.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "Could not write archives import " + "history file.");
        }
    }
    logger.info("Finished importing relay descriptors from local " + "directory:\nParsed " + parsedFiles
            + ", ignored " + ignoredFiles + " files.");
}

From source file:edu.harvard.iq.dataverse.harvest.client.HarvesterServiceBean.java

public void logGetRecordException(Logger hdLogger, OaiHandler oaiHandler, String identifier, Throwable e) {
    String errMessage = "Exception processing getRecord(), oaiUrl=" + oaiHandler.getBaseOaiUrl()
            + ",identifier=" + identifier + " " + e.getClass().getName()
            //+" (exception message suppressed)";
            + " " + e.getMessage();

    hdLogger.log(Level.SEVERE, errMessage);

    // temporary:
    e.printStackTrace();/*from w w  w.  ja  v a 2 s  . co  m*/
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandlerImpl.java

private void traceLoginLogout(final TraceLogDTO params) {
    final Logger logger = getTraceLogger();
    final Level level = TraceLevel.SIMPLE.getLevel();
    if (logger.isLoggable(level)) {
        try {//from  www.j av  a 2 s .c o  m
            logger.log(level, buildActionString(params, false));
        } catch (final Exception e) {
            System.out.println("Error generating log on " + settingsService.getLogSettings().getTraceFile());
        }
    }
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandlerImpl.java

@Override
public void logAccountFeeFinished(final AccountFeeLog feeLog) {
    final Logger logger = getAccountFeeLogger();
    final Level level = AccountFeeLevel.STATUS.getLevel();
    if (logger.isLoggable(level)) {
        try {//from w  w  w  . j ava  2s  .  c  o  m
            logger.log(level, feeLog.getAccountFee().getName() + ": charging has finished");
        } catch (final Exception e) {
            System.out
                    .println("Error generating log on " + settingsService.getLogSettings().getAccountFeeFile());
        }
    }
}

From source file:nl.strohalm.cyclos.utils.logging.LoggingHandlerImpl.java

@Override
public void logAccountFeeStarted(final AccountFeeLog feeLog) {
    final Logger logger = getAccountFeeLogger();
    final Level level = AccountFeeLevel.STATUS.getLevel();
    if (logger.isLoggable(level)) {
        try {//from   www  .  j ava 2 s. c o  m
            logger.log(level, feeLog.getAccountFee().getName() + ": charging has started");
        } catch (final Exception e) {
            System.out
                    .println("Error generating log on " + settingsService.getLogSettings().getAccountFeeFile());
        }
    }
}