List of usage examples for org.apache.commons.logging Log warn
void warn(Object message, Throwable t);
From source file:com.amazon.carbonado.repo.replicated.ReplicatedRepository.java
private <S extends Storable> boolean deleteCorruptEntry(ReplicationTrigger<S> replicationTrigger, S replicaWithKeyOnly, CorruptEncodingException e) throws RepositoryException { if (replicaWithKeyOnly == null) { return false; }/*w w w .ja v a 2s . c o m*/ final Log log = LogFactory.getLog(ReplicatedRepository.class); // Delete corrupt replica entry. try { replicationTrigger.deleteReplica(replicaWithKeyOnly); log.info("Deleted corrupt replica entry: " + replicaWithKeyOnly.toStringKeyOnly(), e); return true; } catch (PersistException e2) { log.warn("Unable to delete corrupt replica entry: " + replicaWithKeyOnly.toStringKeyOnly(), e2); return false; } }
From source file:com.ayovel.nian.exception.XLog.java
private void log(Level level, int loggerMask, String msgTemplate, Object... params) { loggerMask |= STD;//from www.j a va 2s. co m if (isEnabled(level, loggerMask)) { String prefix = getMsgPrefix() != null ? getMsgPrefix() : Info.get().getPrefix(); prefix = (prefix != null && prefix.length() > 0) ? prefix + " " : ""; String msg = prefix + format(msgTemplate, params); Throwable throwable = getCause(params); for (int i = 0; i < LOGGER_MASKS.length; i++) { if (isEnabled(level, loggerMask & LOGGER_MASKS[i])) { Log log = loggers[i]; switch (level) { case FATAL: log.fatal(msg, throwable); break; case ERROR: log.error(msg, throwable); break; case INFO: log.info(msg, throwable); break; case WARN: log.warn(msg, throwable); break; case DEBUG: log.debug(msg, throwable); break; case TRACE: log.trace(msg, throwable); break; } } } } }
From source file:edu.vt.middleware.ldap.LdapTLSSocketFactory.java
/** * This returns a keystore as an <code>InputStream</code>. If the keystore * could not be loaded this method returns null. * * @param filename <code>String</code> to read * @param pt <code>PathType</code> how to read file * * @return <code>InputStream</code> keystore *//*w w w . j a v a 2 s . co m*/ private InputStream getInputStream(final String filename, final PathType pt) { final Log logger = LogFactory.getLog(LdapTLSSocketFactory.class); InputStream is = null; if (pt == PathType.CLASSPATH) { is = LdapTLSSocketFactory.class.getResourceAsStream(filename); } else if (pt == PathType.FILEPATH) { File file; try { file = new File(URI.create(filename)); } catch (IllegalArgumentException e) { file = new File(filename); } try { is = new FileInputStream(file); } catch (IOException e) { if (logger.isWarnEnabled()) { logger.warn("Error loading keystore from " + filename, e); } } } if (is != null) { if (logger.isDebugEnabled()) { logger.debug("Successfully loaded " + filename + " from " + pt); } } else { if (logger.isDebugEnabled()) { logger.debug("Failed to load " + filename + " from " + pt); } } return is; }
From source file:interactivespaces.service.web.server.internal.netty.NettyWebServerService.java
/** * Create a new MIME resolver which maps standard MIME types. * * @param log//from ww w . ja v a2s. c o m * the logger to use while creating the resolver. * * @return the resolver */ private MapExtensionMimeResolver newDefaultMimeResolver(Log log) { MapExtensionMimeResolver resolver = new MapExtensionMimeResolver(); try { InputStream mimeResource = MapExtensionMimeResolver.class.getClassLoader() .getResourceAsStream(BUNDLE_LOCATION_WEB_SERVER_MIME_TYPES); if (mimeResource != null) { String mimeFile = fileSupport.inputStreamAsString(mimeResource); String[] lines = mimeFile.split(MIME_TYPE_LINE_SPLITTER_REGEX); for (String line : lines) { line = line.trim(); if (!line.isEmpty() && !line.startsWith(MIME_FILE_COMMENT_CHARACTER)) { String[] parts = line.split(MIME_FILE_COMPONENT_SPLITTING_REGEX); if (parts.length >= 2) { String mimeType = parts[0]; for (int i = 1; i < parts.length; i++) { resolver.addMimeType(parts[i], mimeType); } } } } } } catch (Exception e) { if (log != null) { log.warn("Could not read MIME file. MIME resolver is empty", e); } } return resolver; }
From source file:name.livitski.tools.springlet.Launcher.java
/** * Configures the manager using command-line arguments. * The arguments are checked in their command line sequence. * If an argument begins with {@link Command#COMMAND_PREFIX}, * its part that follows it is treated as a (long) command's name. * If an argument begins with {@link Command#SWITCH_PREFIX}, * the following character(s) are treated as a switch. * The name or switch extracted this way, prepended with * a bean name prefix for a {@link #BEAN_NAME_PREFIX_COMMAND command} * or a {@link #BEAN_NAME_PREFIX_SWITCH switch}, becomes the name * of a bean to look up in the framework's * {@link #MAIN_BEAN_CONFIG_FILE configuration file(s)}. * The bean that handles a command must extend the * {@link Command} class. Once a suitable bean is found, * it is called to act upon the command or switch and process * any additional arguments associated with it. * If no bean can be found or the argument is not prefixed * properly, it is considered unclaimed. You may configure a * special subclass of {@link Command} to process such arguments * by placing a bean named {@link #BEAN_NAME_DEFAULT_HANDLER} on * the configuration. If there is no such bean configured, or when * any {@link Command} bean throws an exception while processing * a command, a command line error is reported and the application * quits./*from w w w . ja v a 2 s .c om*/ * @param args the command line * @return this manager object */ public Launcher withArguments(String[] args) { configureDefaultLogging(); final Log log = log(); ListIterator<String> iargs = Arrays.asList(args).listIterator(); while (iargs.hasNext()) { String arg = iargs.next(); String prefix = null; String beanPrefix = null; Command cmd = null; if (arg.startsWith(Command.COMMAND_PREFIX)) prefix = Command.COMMAND_PREFIX; else if (arg.startsWith(Command.SWITCH_PREFIX)) prefix = Command.SWITCH_PREFIX; if (null != prefix) { arg = arg.substring(prefix.length()); beanPrefix = Command.SWITCH_PREFIX == prefix ? BEAN_NAME_PREFIX_SWITCH : BEAN_NAME_PREFIX_COMMAND; try { cmd = getBeanFactory().getBean(beanPrefix + arg, Command.class); } catch (NoSuchBeanDefinitionException noBean) { log.debug("Could not find a handler for command-line argument " + prefix + arg, noBean); } } if (null == cmd) { iargs.previous(); try { cmd = getBeanFactory().getBean(BEAN_NAME_DEFAULT_HANDLER, Command.class); } catch (RuntimeException ex) { log.error("Unknown command line argument: " + (null != prefix ? prefix : "") + arg, ex); status = STATUS_COMMAND_PARSING_FAILURE; break; } } try { cmd.process(iargs); } catch (SkipApplicationRunRequest skip) { if (log.isTraceEnabled()) log.trace("Handler for argument " + (null != prefix ? prefix : "") + arg + " requested to skip the application run", skip); status = STATUS_RUN_SKIPPED; break; } catch (RuntimeException err) { log.error("Invalid command line argument(s) near " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); status = STATUS_COMMAND_PARSING_FAILURE; break; } catch (ApplicationBeanException err) { log.error("Error processing command line argument " + (null != prefix ? prefix : "") + arg + ": " + err.getMessage(), err); try { err.updateBeanStatus(); } catch (RuntimeException noStatus) { final ApplicationBean appBean = err.getApplicationBean(); log.warn("Could not obtain status code" + (null != appBean ? " from " + appBean : ""), noStatus); status = STATUS_INTERNAL_ERROR; } break; } } return this; }
From source file:org.acmsl.queryj.api.AbstractTemplateGenerator.java
/** * Serializes given template./*ww w.jav a2s. c o m*/ * @param template the template. * @param outputFilePath the output file path. */ protected void serializeTemplate(@NotNull final N template, @NotNull final String outputFilePath) { ObjectOutputStream t_osCache = null; try { @NotNull final File outputFile = new File(outputFilePath); @NotNull final File baseFolder = outputFile.getParentFile(); if (!baseFolder.exists()) { if (!baseFolder.mkdirs()) { throw new IOException(baseFolder + " does not exist and cannot be created"); } } if (!baseFolder.canWrite()) { throw new IOException(baseFolder + " is not writable"); } t_osCache = new ObjectOutputStream(new FileOutputStream(new File(outputFilePath))); t_osCache.writeObject(template); } catch (@NotNull final IOException cannotSerialize) { @Nullable final Log t_Log = UniqueLogFactory.getLog(AbstractQueryJTemplateGenerator.class); if (t_Log != null) { t_Log.warn(CANNOT_SERIALIZE_TEMPLATE_LITERAL + outputFilePath + " (" + cannotSerialize + ")", cannotSerialize); } } finally { if (t_osCache != null) { try { t_osCache.close(); } catch (@NotNull final IOException cannotCloseCacheFile) { @Nullable final Log t_Log = UniqueLogFactory.getLog(AbstractQueryJTemplateGenerator.class); if (t_Log != null) { t_Log.warn(CANNOT_SERIALIZE_TEMPLATE_LITERAL + outputFilePath + " (" + cannotCloseCacheFile + ")", cannotCloseCacheFile); } } } } }
From source file:org.acmsl.queryj.api.handlers.AbstractTemplateWritingHandler.java
/** * Writes the templates.// ww w. ja va2 s. c o m * @param templates the templates. * @param parameters the parameters. * @param charset the file encoding. * @param templateGenerator the template generator. * @param rootDir the root dir. * @throws QueryJBuildException if the templates cannot be written. */ @SuppressWarnings("unused") protected void writeTemplatesSequentially(@Nullable final List<T> templates, @NotNull final QueryJCommand parameters, @NotNull final Charset charset, @NotNull final TG templateGenerator, @NotNull final File rootDir) throws QueryJBuildException { if (templates != null) { for (@Nullable final T t_Template : templates) { if (t_Template != null) { try { templateGenerator.write(t_Template, retrieveOutputDir(t_Template.getTemplateContext(), rootDir, parameters), rootDir, charset); } catch (@NotNull final IOException ioException) { @Nullable final Log t_Log = UniqueLogFactory.getLog(AbstractTemplateWritingHandler.class); if (t_Log != null) { t_Log.warn("Error writing template", ioException); } } } } } }
From source file:org.acmsl.queryj.customsql.handlers.customsqlvalidation.BindQueryParametersHandler.java
/** * Binds the parameters to given statement. * @param parameter the {@link Parameter}. * @param parameterIndex the parameter index. * @param sql the sql./*from www. j a v a 2 s. c o m*/ * @param statement the prepared statement. * @param typeManager the metadata type manager. * @param conversionUtils the <code>ConversionUtils</code> instance. * @param <T> the type. * @throws QueryJBuildException if the binding fails. */ @SuppressWarnings("unchecked") protected <T> void bindParameter(@NotNull final Parameter<String, T> parameter, final int parameterIndex, @NotNull final Sql<String> sql, @NotNull final PreparedStatement statement, @NotNull final TypeManager typeManager, @NotNull final ConversionUtils conversionUtils) throws QueryJBuildException { @Nullable QueryJBuildException exceptionToThrow = null; @Nullable final Log t_Log = UniqueLogFactory.getLog(CustomSqlValidationHandler.class); @Nullable final Method t_Method; @Nullable final Collection<Class<?>> t_cParameterClasses; @Nullable final Class<T> t_Type = retrieveType(parameter, typeManager); if (t_Type != null) { if (typeManager.isPrimitiveWrapper(t_Type)) { t_cParameterClasses = Arrays.asList(Integer.TYPE, typeManager.toPrimitive(t_Type)); } else { t_cParameterClasses = Arrays.asList(Integer.TYPE, t_Type); } t_Method = retrievePreparedStatementMethod(parameter, parameterIndex, t_Type, sql, t_cParameterClasses); @Nullable final Object t_ParameterValue = retrieveParameterValue(parameter, parameterIndex, t_Type.getSimpleName(), t_Type, sql, conversionUtils); try { t_Method.invoke(statement, parameterIndex + 1, t_ParameterValue); } catch (@NotNull final IllegalAccessException illegalAccessException) { if (t_Log != null) { t_Log.warn(COULD_NOT_BIND_PARAMETER_VIA + PREPARED_STATEMENT_SET + t_Type.getSimpleName() + "(int, " + t_Type.getName() + ")", illegalAccessException); } exceptionToThrow = new UnsupportedCustomSqlParameterTypeException(t_Type.getSimpleName(), parameterIndex + 1, parameter.getName(), sql, illegalAccessException); } catch (@NotNull final InvocationTargetException invocationTargetException) { if (t_Log != null) { t_Log.warn(COULD_NOT_BIND_PARAMETER_VIA + PREPARED_STATEMENT_SET + t_Type.getSimpleName() + "(int, " + t_Type.getName() + ")", invocationTargetException); } exceptionToThrow = new UnsupportedCustomSqlParameterTypeException(t_Type.getSimpleName(), parameterIndex + 1, parameter.getName(), sql, invocationTargetException); } } if (exceptionToThrow != null) { throw exceptionToThrow; } }
From source file:org.acmsl.queryj.customsql.handlers.customsqlvalidation.RetrieveResultPropertiesHandler.java
/** * Executes the <code>ResultSet.getXXX</code> method. * @param method the <code>ResultSet</code> getter method for given property. * @param resultSet the {@link ResultSet} instance. * @param property the property./* ww w .j ava 2 s . c om*/ * @param sqlResult the {@link Result} instance. * @param sql the SQL element. * @param metadataManager the {@link MetadataManager} instance. * @throws QueryJBuildException if the getter information is unavailable. */ protected void invokeResultSetGetter(@NotNull final Method method, @NotNull final ResultSet resultSet, @NotNull final Property<String> property, @Nullable final Result<String> sqlResult, @NotNull final Sql<String> sql, @NotNull final MetadataManager metadataManager) throws QueryJBuildException { @Nullable final Log t_Log = UniqueLogFactory.getLog(CustomSqlValidationHandler.class); try { @NotNull final Object[] t_aParameters = new Object[1]; t_aParameters[0] = property.getColumnName(); method.invoke(resultSet, t_aParameters); } catch (@NotNull final Throwable cannotRetrieveColumnValue) { if (t_Log != null) { t_Log.warn(VALIDATION_FAILED_FOR + sql.getId() + ":\n" + COULD_NOT_RETRIEVE_RESULT_VIA + RESULT_SET + method.getName() + "(" + ((property.getIndex() > 0) ? "" + property.getIndex() : property.getColumnName()) + ")", cannotRetrieveColumnValue); } if (metadataManager.isInvalidColumnNameException(cannotRetrieveColumnValue)) { throw new InvalidColumnNameInCustomResultException(property, sql, sqlResult, cannotRetrieveColumnValue); } else if (metadataManager.isInvalidColumnTypeException(cannotRetrieveColumnValue)) { throw new UnsupportedCustomResultPropertyTypeException(property, sql, sqlResult, cannotRetrieveColumnValue); } } }
From source file:org.acmsl.queryj.metadata.engines.AbstractJdbcMetadataManager.java
/** * Logs a warning message./* w w w .j av a 2s . c o m*/ * @param message the message to log. * @param exception the exception */ protected void logWarn(@NotNull final String message, @NotNull final Exception exception) { @Nullable final Log t_Log = UniqueLogFactory.getLog(AbstractJdbcMetadataManager.class); if (t_Log != null) { t_Log.warn(message, exception); } }