List of usage examples for java.util.logging Logger isLoggable
public boolean isLoggable(Level level)
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandlerImpl.java
@Override public void trace(final TraceLogDTO params) { final Logger logger = getTraceLogger(); boolean isError = params.getError() != null; final Level detailed = TraceLevel.DETAILED.getLevel(); final boolean detailedLoggable = logger.isLoggable(detailed); boolean logParameters = detailedLoggable; Level logLevel;/*from w ww . j a va 2 s . c o m*/ if (isError) { final Level error = TraceLevel.ERRORS.getLevel(); final boolean errorLoggable = logger.isLoggable(error); logLevel = errorLoggable ? error : null; } else { if (traceWritesOnly && !params.isHasDatabaseWrites()) { return; } final Level normal = TraceLevel.SIMPLE.getLevel(); final boolean normalLoggable = logger.isLoggable(normal); logLevel = detailedLoggable ? detailed : normalLoggable ? normal : null; } if (logLevel != null) { final String message = buildActionString(params, logParameters); try { logger.log(logLevel, message, params.getError()); } catch (final Exception e) { System.out.println("Error generating log on " + settingsService.getLogSettings().getTraceFile()); } } }
From source file:nl.strohalm.cyclos.utils.logging.LoggingHandlerImpl.java
private WebServiceLogPrepareResult prepareWebService(final Logger logger, final boolean isError) { Level logLevel;//w w w . ja va2 s. c o m final Level detailed = WebServiceLevel.DETAILED.getLevel(); final boolean detailedLoggable = logger.isLoggable(detailed); boolean logParameters = detailedLoggable; if (isError) { final Level error = WebServiceLevel.ERRORS.getLevel(); final boolean errorLoggable = logger.isLoggable(error); logLevel = errorLoggable ? error : null; } else { final Level normal = WebServiceLevel.SIMPLE.getLevel(); final boolean normalLoggable = logger.isLoggable(normal); logLevel = detailedLoggable ? detailed : normalLoggable ? normal : null; } return new WebServiceLogPrepareResult(logLevel, logParameters); }
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 {/* w ww. j a v a 2 s .c om*/ logger.log(level, buildActionString(params, false)); } catch (final Exception e) { System.out.println("Error generating log on " + settingsService.getLogSettings().getTraceFile()); } } }
From source file:org.apache.cxf.common.logging.LogUtils.java
/** * Allows both parameter substitution and a typed Throwable to be logged. * * @param logger the Logger the log to/*from w w w .j a va 2s . c om*/ * @param level the severity level * @param message the log message * @param throwable the Throwable to log * @param parameter the parameter to substitute into message */ public static void log(Logger logger, Level level, String message, Throwable throwable, Object parameter) { if (logger.isLoggable(level)) { final String formattedMessage = MessageFormat.format(localize(logger, message), parameter); doLog(logger, level, formattedMessage, throwable); } }
From source file:org.apache.cxf.common.logging.LogUtils.java
/** * Allows both parameter substitution and a typed Throwable to be logged. * * @param logger the Logger the log to/*www .j av a2s . c o m*/ * @param level the severity level * @param message the log message * @param throwable the Throwable to log * @param parameters the parameters to substitute into message */ public static void log(Logger logger, Level level, String message, Throwable throwable, Object... parameters) { if (logger.isLoggable(level)) { final String formattedMessage = MessageFormat.format(localize(logger, message), parameters); doLog(logger, level, formattedMessage, throwable); } }
From source file:org.apache.cxf.common.logging.LogUtils.java
/** * Checks log level and logs/*from ww w . j a v a 2 s.c o m*/ * * @param logger the Logger the log to * @param level the severity level * @param message the log message * @param parameters the parameters to substitute into message */ public static void log(Logger logger, Level level, String message, Object[] parameters) { if (logger.isLoggable(level)) { String msg = localize(logger, message); try { msg = MessageFormat.format(msg, parameters); } catch (IllegalArgumentException ex) { //ignore, log as is } doLog(logger, level, msg, null); } }
From source file:org.apache.reef.util.logging.LoggingScopeImpl.java
/** * A constructor of ReefLoggingScope. It starts the timer and logs the msg * * @param logger//from w ww . j a v a 2s .c o m * @param msg * @param params */ LoggingScopeImpl(final Logger logger, final Level logLevel, final String msg, final Object[] params) { this.logger = logger; this.logLevel = logLevel; this.msg = msg; this.params = params; stopWatch.start(); this.optionalParams = Optional.ofNullable(params); if (logger.isLoggable(logLevel)) { final StringBuilder sb = new StringBuilder(); log(sb.append(START_PREFIX).append(msg).toString()); } }
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 ww w.j a va 2 s.c om*/ 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.geoserver.wfs.json.JSONType.java
/** * Handle Exception in JSON and JSONP format * /*w w w . jav a 2 s. c om*/ * @param LOGGER the logger to use (can be null) * @param exception the exception to write to the response outputStream * @param request the request generated the exception * @param charset the desired charset * @param verbose be verbose * @param isJsonp switch writing json (false) or jsonp (true) */ public static void handleJsonException(Logger LOGGER, ServiceException exception, Request request, String charset, boolean verbose, boolean isJsonp) { final HttpServletResponse response = request.getHttpResponse(); // TODO: server encoding options? response.setCharacterEncoding(charset); ServletOutputStream os = null; try { os = response.getOutputStream(); if (isJsonp) { // jsonp response.setContentType(JSONType.jsonp); JSONType.writeJsonpException(exception, request, os, charset, verbose); } else { // json OutputStreamWriter outWriter = null; try { outWriter = new OutputStreamWriter(os, charset); response.setContentType(JSONType.json); JSONType.writeJsonException(exception, request, outWriter, verbose); } finally { if (outWriter != null) { try { outWriter.flush(); } catch (IOException ioe) { } IOUtils.closeQuietly(outWriter); } } } } catch (Exception e) { if (LOGGER != null && LOGGER.isLoggable(Level.SEVERE)) LOGGER.severe(e.getLocalizedMessage()); } finally { if (os != null) { try { os.flush(); } catch (IOException ioe) { } IOUtils.closeQuietly(os); } } }
From source file:org.jdesktop.wonderland.modules.service.InstallManager.java
/** * Adds a new module to installed. This simply copies files, it assumes all * preparations or checks have already been performed. It is given the * module and the File root of where to copy and returns the Module object * representing the installed module//ww w. jav a 2 s. com */ public Module add(String moduleName, File root) { /* The error logger */ Logger logger = ModuleManager.getLogger(); /* * Expand the contents of the module to the installed/ directory. First * create a directory holding the module (but check first if it already * exists and log a warning message). */ File file = new File(this.installedFile, moduleName); if (ModuleManagerUtils.makeCleanDirectory(file) == false) { logger.log(Level.WARNING, "[MODULES] INSTALL Failed to Create " + file.getAbsolutePath()); return null; } /* Next, expand the contents of the module into this directory */ try { FileUtils.copyDirectory(root, file); } catch (java.io.IOException excp) { logger.log(Level.WARNING, "[MODULES] INSTALL Failed to Copy " + root.getAbsolutePath() + " To " + file.getAbsolutePath(), excp); return null; } /* Re-open module in the installed directory, add to the list */ Module module = null; try { module = ModuleFactory.open(file); this.installedModules.put(moduleName, module); if (logger.isLoggable(Level.FINE)) { logger.fine("Add installed module " + module); } } catch (java.lang.Exception excp) { /* Log the error and return false */ logger.log(Level.WARNING, "[MODULES] PENDING Failed to Open Module", excp); return null; } return module; }