public static CommandOutputContent runOnNode(Node node, String name, String... command) { String content = "Exception occurred while retrieving command content"; VirtualChannel chan = node.getChannel(); if (chan == null) { content = "No connection to node"; } else { try { content = chan.call(new CommandLauncher(command)); } catch (IOException e) { final LogRecord lr = new LogRecord(Level.FINE, "Could not retrieve command content from {0}"); lr.setParameters(new Object[] {getNodeName(node)}); lr.setThrown(e); LOGGER.log(lr); } catch (InterruptedException e) { final LogRecord lr = new LogRecord(Level.FINE, "Could not retrieve command content from {0}"); lr.setParameters(new Object[] {getNodeName(node)}); lr.setThrown(e); LOGGER.log(lr); } } return new CommandOutputContent(name, content); }
public SVNNodeKind checkRepositoryPath( SCMSourceOwner context, SVNURL repoURL, StandardCredentials credentials) throws SVNException { SVNRepository repository = null; try { repository = getRepository( context, repoURL, credentials, Collections.<String, Credentials>emptyMap(), null); repository.testConnection(); long rev = repository.getLatestRevision(); String repoPath = getRelativePath(repoURL, repository); return repository.checkPath(repoPath, rev); } catch (SVNException e) { if (LOGGER.isLoggable(Level.FINE)) { LogRecord lr = new LogRecord( Level.FINE, "Could not check repository path {0} using credentials {1} ({2})"); lr.setThrown(e); lr.setParameters( new Object[] { repoURL, credentials == null ? null : CredentialsNameProvider.name(credentials), credentials }); LOGGER.log(lr); } throw e; } finally { if (repository != null) repository.closeSession(); } }
public final Client performLogin(final ServerLogin login) throws RjException, LoginException { String client = null; try { client = getCallingClient(); if (login.getId() != this.pendingLoginId || !client.equals(this.pendingLoginClient)) { throw new FailedLoginException("Login process was interrupted by another client."); } login.readAnswer(this.usePubkeyExchange ? this.pendingLoginKeyPair.getPrivate() : null); this.pendingLoginKeyPair = null; final String name = doPerformLogin(login.getCallbacks()); LOGGER.log( Level.INFO, "{0} performing login completed successfull: {1} ({2}).", new Object[] {this.logPrefix, name, client}); return new Client(name, getCallingClient(), (byte) 0); } catch (final Exception e) { if (e instanceof LoginException) { final LogRecord log = new LogRecord(Level.INFO, "{0} performing login failed ({1})."); log.setParameters(new Object[] {this.logPrefix, client}); log.setThrown(e); LOGGER.log(log); throw (LoginException) e; } if (e instanceof RjException) { throw (RjException) e; } throw new RjException( "An unexpected error occurred when validating the login credential.", e); } finally { System.gc(); } }
protected void log(Level level, String message, Object[] params, Throwable cause) { if (logger.isLoggable(level)) { LogRecord record = new LogRecord(level, message); record.setParameters(params); record.setThrown(cause); logger.log(record); } }
/** * Log the message at the specified level with the specified exception if any. * * @param level The level to log at. * @param message The message to log. * @param e The exception, if any. */ private void log(Level level, String message, Exception e) { // millis and thread are filled by the constructor LogRecord record = new LogRecord(level, message); record.setLoggerName(logger.getName()); record.setThrown(e); record.setSourceClassName(logger.getName()); record.setSourceMethodName(getMethodName()); logger.log(record); }
protected void log(Throwable t, Level level, String msg, Object[] objs) { LogRecord lr = createLogRecord(level, msg); if (t != null) { lr.setThrown(t); } if (objs != null) { // serializeCheck(objs); lr.setParameters(objs); } getLogger().log(lr); }
public void logp( Level level, String sourceClass, String sourceMethod, String message, Throwable thrown) { synchronized (lock) { LogRecord rec = new LogRecord(level, message); rec.setResourceBundle(resourceBundle); rec.setSourceClassName(sourceClass); rec.setSourceMethodName(sourceMethod); rec.setThrown(thrown); log(rec); } }
/** * Register the "RecodeNoData" image operation to the operation registry of the specified JAI * instance. */ public static void register(final JAI jai) { final OperationRegistry registry = jai.getOperationRegistry(); try { registry.registerDescriptor(new Descriptor()); registry.registerFactory( RenderedRegistryMode.MODE_NAME, OPERATION_NAME, "geotools.org", new CRIF()); } catch (IllegalArgumentException exception) { final LogRecord record = Loggings.format(Level.SEVERE, LoggingKeys.CANT_REGISTER_JAI_OPERATION_$1, OPERATION_NAME); record.setSourceMethodName("<classinit>"); record.setThrown(exception); record.setLoggerName(LOGGER.getName()); LOGGER.log(record); } }
public synchronized void run(boolean includeSubdir) { markInProgress(); try { deployAll(directory, includeSubdir); undeployAll(directory, includeSubdir); } catch (AutoDeploymentException e) { // print and continue LogRecord lr = new LogRecord(Level.SEVERE, EXCEPTION_CAUGHT); Object args[] = {e.getMessage()}; lr.setParameters(args); lr.setThrown(e); deplLogger.log(lr); } finally { clearInProgress(); } }
protected void logp( Object clazz, String methodName, Throwable t, Level level, String msg, Object[] objs) { LogRecord lr = createLogRecord(level, msg); if (t != null) { lr.setThrown(t); } if (clazz != null) { lr.setSourceClassName(toClassName(clazz)); } if (methodName != null) { lr.setSourceMethodName(methodName); } if (objs != null) { // serializeCheck(objs); lr.setParameters(objs); } getLogger().log(lr); }
/** Invoked when a factory can't be loaded. Log a warning, but do not stop the process. */ private static void loadingFailure( final Class<?> category, final Throwable error, final boolean showStackTrace) { final String name = Classes.getShortName(category); final StringBuilder cause = new StringBuilder(Classes.getShortClassName(error)); final String message = error.getLocalizedMessage(); if (message != null) { cause.append(": "); cause.append(message); } final LogRecord record = Loggings.format(Level.WARNING, LoggingKeys.CANT_LOAD_SERVICE_$2, name, cause.toString()); if (showStackTrace) { record.setThrown(error); } record.setSourceClassName(FactoryRegistry.class.getName()); record.setSourceMethodName("scanForPlugins"); record.setLoggerName(LOGGER.getName()); LOGGER.log(record); }
/** * Returns {@code true} if this factory is available. The default implementation returns {@code * false} if no backing store were setup and {@link DeferredAuthorityFactory#createBackingStore} * throws an exception. */ @Override synchronized boolean isAvailable() { try { return getBackingStore().isAvailable(); } catch (FactoryNotFoundException exception) { /* * The factory is not available. This is error may be normal; it happens * for example if no gt2-epsg-hsql.jar (or similar JAR) are found in the * classpath, which is the case for example in GeoServer 1.3. Do not log * any stack trace, since stack traces suggest more serious errors than * what we really have here. */ } catch (FactoryException exception) { /* * The factory creation failed for an other reason, which may be more * serious. Now it is time to log a warning with a stack trace. */ final Citation citation = getAuthority(); final Collection titles = citation.getAlternateTitles(); InternationalString title = citation.getTitle(); if (titles != null) { for (final Iterator it = titles.iterator(); it.hasNext(); ) { /* * Uses the longuest title instead of the main one. In Geotools * implementation, the alternate title may contains usefull informations * like the EPSG database version number and the database engine. */ final InternationalString candidate = (InternationalString) it.next(); if (candidate.length() > title.length()) { title = candidate; } } } final LogRecord record = Loggings.format(Level.WARNING, LoggingKeys.UNAVAILABLE_AUTHORITY_FACTORY_$1, title); record.setSourceClassName(getClass().getName()); record.setSourceMethodName("isAvailable"); record.setThrown(exception); record.setLoggerName(LOGGER.getName()); LOGGER.log(record); } return false; }
public static CommandOutputContent runOnNodeAndCache( WeakHashMap<Node, String> cache, Node node, String name, String... command) { String content = "Exception occurred while retrieving command content"; try { content = AsyncResultCache.get( node, cache, new CommandLauncher(command), "sysctl info", "N/A: Either no connection to node or no cached result"); } catch (IOException e) { final LogRecord lr = new LogRecord(Level.FINE, "Could not retrieve sysctl content from {0}"); lr.setParameters(new Object[] {getNodeName(node)}); lr.setThrown(e); LOGGER.log(lr); } return new CommandOutputContent(name, content); }
/** * Implementation of {@link #unexpectedException(Logger, Class, String, Throwable)}. * * @param logger Where to log the error, or {@code null}. * @param classe The fully qualified class name where the error occurred, or {@code null}. * @param method The method where the error occurred, or {@code null}. * @param error The error. * @param level The logging level. * @return {@code true} if the error has been logged, or {@code false} if the logger doesn't log * anything at the specified level. */ private static boolean unexpectedException( Logger logger, String classe, String method, final Throwable error, final Level level) { /* * Checks if loggable, inferring the logger from the classe name if needed. */ if (error == null) { return false; } if (logger == null && classe != null) { final int separator = classe.lastIndexOf('.'); final String paquet = (separator >= 1) ? classe.substring(0, separator - 1) : ""; logger = getLogger(paquet); } if (logger != null && !logger.isLoggable(level)) { return false; } /* * Loggeable, so complete the null argument from the stack trace if we can. */ if (logger == null || classe == null || method == null) { String paquet = (logger != null) ? logger.getName() : null; final StackTraceElement[] elements = error.getStackTrace(); for (int i = 0; i < elements.length; i++) { /* * Searchs for the first stack trace element with a classname matching the * expected one. We compare preferably against the name of the class given * in argument, or against the logger name (taken as the package name) otherwise. */ final StackTraceElement element = elements[i]; final String classname = element.getClassName(); if (classe != null) { if (!classname.equals(classe)) { continue; } } else if (paquet != null) { if (!classname.startsWith(paquet)) { continue; } final int length = paquet.length(); if (classname.length() > length) { // We expect '.' but we accept also '$' or end of string. final char separator = classname.charAt(length); if (Character.isJavaIdentifierPart(separator)) { continue; } } } /* * Now that we have a stack trace element from the expected class (or any * element if we don't know the class), make sure that we have the right method. */ final String methodName = element.getMethodName(); if (method != null && !methodName.equals(method)) { continue; } /* * Now computes every values that are null, and stop the loop. */ if (paquet == null) { final int separator = classname.lastIndexOf('.'); paquet = (separator >= 1) ? classname.substring(0, separator - 1) : ""; logger = getLogger(paquet); if (!logger.isLoggable(level)) { return false; } } if (classe == null) { classe = classname; } if (method == null) { method = methodName; } break; } /* * The logger may stay null if we have been unable to find a suitable * stack trace. Fallback on the global logger. * * TODO: Use GLOBAL_LOGGER_NAME constant when we will be allowed to target Java 6. */ if (logger == null) { logger = getLogger("global"); if (!logger.isLoggable(level)) { return false; } } } /* * Now prepare the log message. If we have been unable to figure out a source class and * method name, we will fallback on Java logging default mechanism, which may returns a * less relevant name than our attempt to use the logger name as the package name. */ final StringBuilder buffer = new StringBuilder(Classes.getShortClassName(error)); final String message = error.getLocalizedMessage(); if (message != null) { buffer.append(": ").append(message); } final LogRecord record = new LogRecord(level, buffer.toString()); if (classe != null) { record.setSourceClassName(classe); } if (method != null) { record.setSourceMethodName(method); } if (level.intValue() > 500) { record.setThrown(error); } record.setLoggerName(logger.getName()); logger.log(record); return true; }