Example usage for org.apache.commons.logging Log warn

List of usage examples for org.apache.commons.logging Log warn

Introduction

In this page you can find the example usage for org.apache.commons.logging Log warn.

Prototype

void warn(Object message, Throwable t);

Source Link

Document

Logs an error with warn log level.

Usage

From source file:org.apache.ftpserver.command.SITE.java

/**
 * Execute command.// w w  w . j a v  a 2  s .c o m
 */
public void execute(RequestHandler handler, FtpRequestImpl request, FtpWriter out)
        throws IOException, FtpException {

    // call Ftplet.onSite method
    IFtpConfig fconfig = handler.getConfig();
    Ftplet ftpletContainer = fconfig.getFtpletContainer();
    FtpletEnum ftpletRet = ftpletContainer.onSite(request, out);
    if (ftpletRet == FtpletEnum.RET_SKIP) {
        return;
    } else if (ftpletRet == FtpletEnum.RET_DISCONNECT) {
        fconfig.getConnectionManager().closeConnection(handler);
        return;
    }

    // get request name
    String argument = request.getArgument();
    if (argument != null) {
        int spaceIndex = argument.indexOf(' ');
        if (spaceIndex != -1) {
            argument = argument.substring(0, spaceIndex);
        }
        argument = argument.toUpperCase();
    }

    // no params
    if (argument == null) {
        request.resetState();
        out.send(200, "SITE", null);
        return;
    }

    // call appropriate command method
    String siteRequest = "SITE_" + argument;
    Command command = (Command) COMMAND_MAP.get(siteRequest);
    try {
        if (command != null) {
            command.execute(handler, request, out);
        } else {
            request.resetState();
            out.send(502, "SITE.not.implemented", argument);
        }
    } catch (Exception ex) {
        Log log = fconfig.getLogFactory().getInstance(getClass());
        log.warn("SITE.execute()", ex);
        request.resetState();
        out.send(500, "SITE", null);
    }

}

From source file:org.apache.hadoop.service.ServiceOperations.java

/**
 * Stop a service; if it is null do nothing. Exceptions are caught and
 * logged at warn level. (but not Throwables). This operation is intended to
 * be used in cleanup operations/*from  w  w  w .  j  a v  a  2s  .c  om*/
 *
 * @param log the log to warn at
 * @param service a service; may be null
 * @return any exception that was caught; null if none was.
 * @see ServiceOperations#stopQuietly(Service)
 */
public static Exception stopQuietly(Log log, Service service) {
    try {
        stop(service);
    } catch (Exception e) {
        log.warn("When stopping the service " + service.getName() + " : " + e, e);
        return e;
    }
    return null;
}

From source file:org.apache.hadoop.yarn.server.resourcemanager.RMServerUtils.java

/**
 * Utility method to verify if the current user has access based on the
 * passed {@link AccessControlList}//from  ww  w.  ja v a  2s . com
 *
 * @param authorizer the {@link AccessControlList} to check against
 * @param method     the method name to be logged
 * @param module     like AdminService or NodeLabelManager
 * @param LOG        the logger to use
 * @return {@link UserGroupInformation} of the current user
 * @throws IOException
 */
public static UserGroupInformation verifyAdminAccess(YarnAuthorizationProvider authorizer, String method,
        String module, final Log LOG) throws IOException {
    UserGroupInformation user;
    try {
        user = UserGroupInformation.getCurrentUser();
    } catch (IOException ioe) {
        LOG.warn("Couldn't get current user", ioe);
        RMAuditLogger.logFailure("UNKNOWN", method, "", "AdminService", "Couldn't get current user");
        throw ioe;
    }

    if (!authorizer.isAdmin(user)) {
        LOG.warn("User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'");

        RMAuditLogger.logFailure(user.getShortUserName(), method, "", module,
                RMAuditLogger.AuditConstants.UNAUTHORIZED_USER);

        throw new AccessControlException(
                "User " + user.getShortUserName() + " doesn't have permission" + " to call '" + method + "'");
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace(method + " invoked by user " + user.getShortUserName());
    }
    return user;
}

From source file:org.apache.hadoop.yarn.util.AdHocLogDumper.java

public void dumpLogs(String level, int timePeriod) throws YarnRuntimeException, IOException {
    synchronized (lock) {
        if (logFlag) {
            LOG.info("Attempt to dump logs when appender is already running");
            throw new YarnRuntimeException("Appender is already dumping logs");
        }//ww  w. ja v a  2s  .  c  o m
        Level targetLevel = Level.toLevel(level);
        Log log = LogFactory.getLog(name);
        appenderLevels.clear();
        if (log instanceof Log4JLogger) {
            Logger packageLogger = ((Log4JLogger) log).getLogger();
            currentLogLevel = packageLogger.getLevel();
            Level currentEffectiveLevel = packageLogger.getEffectiveLevel();

            // make sure we can create the appender first
            Layout layout = new PatternLayout("%d{ISO8601} %p %c: %m%n");
            FileAppender fApp;
            File file = new File(System.getProperty("yarn.log.dir"), targetFilename);
            try {
                fApp = new FileAppender(layout, file.getAbsolutePath(), false);
            } catch (IOException ie) {
                LOG.warn("Error creating file, can't dump logs to " + file.getAbsolutePath(), ie);
                throw ie;
            }
            fApp.setName(AdHocLogDumper.AD_HOC_DUMPER_APPENDER);
            fApp.setThreshold(targetLevel);

            // get current threshold of all appenders and set it to the effective
            // level
            for (Enumeration appenders = Logger.getRootLogger().getAllAppenders(); appenders
                    .hasMoreElements();) {
                Object obj = appenders.nextElement();
                if (obj instanceof AppenderSkeleton) {
                    AppenderSkeleton appender = (AppenderSkeleton) obj;
                    appenderLevels.put(appender.getName(), appender.getThreshold());
                    appender.setThreshold(currentEffectiveLevel);
                }
            }

            packageLogger.addAppender(fApp);
            LOG.info("Dumping adhoc logs for " + name + " to " + file.getAbsolutePath() + " for " + timePeriod
                    + " milliseconds");
            packageLogger.setLevel(targetLevel);
            logFlag = true;

            TimerTask restoreLogLevel = new RestoreLogLevel();
            Timer restoreLogLevelTimer = new Timer();
            restoreLogLevelTimer.schedule(restoreLogLevel, timePeriod);
        }
    }
}

From source file:org.apache.http.conn.util.PublicSuffixMatcherLoader.java

public static PublicSuffixMatcher getDefault() {
    if (DEFAULT_INSTANCE == null) {
        synchronized (PublicSuffixMatcherLoader.class) {
            if (DEFAULT_INSTANCE == null) {
                final URL url = PublicSuffixMatcherLoader.class.getResource("/mozilla/public-suffix-list.txt");
                if (url != null) {
                    try {
                        DEFAULT_INSTANCE = load(url);
                    } catch (IOException ex) {
                        // Should never happen
                        final Log log = LogFactory.getLog(PublicSuffixMatcherLoader.class);
                        if (log.isWarnEnabled()) {
                            log.warn("Failure loading public suffix list from default resource", ex);
                        }/* w  w w.  j av a2s .  c om*/
                    }
                } else {
                    DEFAULT_INSTANCE = new PublicSuffixMatcher(Arrays.asList("com"), null);
                }
            }
        }
    }
    return DEFAULT_INSTANCE;
}

From source file:org.apache.http.HC4.conn.util.PublicSuffixMatcherLoader.java

public static PublicSuffixMatcher getDefault() {
    if (DEFAULT_INSTANCE == null) {
        synchronized (PublicSuffixMatcherLoader.class) {
            if (DEFAULT_INSTANCE == null) {
                final URL url = PublicSuffixMatcherLoader.class.getResource("mozilla/public-suffix-list.txt");
                if (url != null) {
                    try {
                        DEFAULT_INSTANCE = load(url);
                    } catch (IOException ex) {
                        // Should never happen
                        final Log log = LogFactory.getLog(PublicSuffixMatcherLoader.class);
                        if (log.isWarnEnabled()) {
                            log.warn("Failure loading public suffix list from default resource", ex);
                        }//from w w  w.  j  a va 2  s .c om
                    }
                } else {
                    DEFAULT_INSTANCE = new PublicSuffixMatcher(Arrays.asList("com"), null);
                }
            }
        }
    }
    return DEFAULT_INSTANCE;
}

From source file:org.apache.http.HC4.nio.conn.ssl.SSLIOSessionStrategy.java

private static PublicSuffixMatcher getDefaultPublicSuffixMatcher() {
    if (DEFAULT_INSTANCE == null) {
        synchronized (PublicSuffixMatcherLoader.class) {
            if (DEFAULT_INSTANCE == null) {
                final URL url = PublicSuffixMatcherLoader.class.getResource("/mozilla/public-suffix-list.txt");
                if (url != null) {
                    try {
                        DEFAULT_INSTANCE = PublicSuffixMatcherLoader.load(url);
                    } catch (IOException ex) {
                        // Should never happen
                        final Log log = LogFactory.getLog(PublicSuffixMatcherLoader.class);
                        if (log.isWarnEnabled()) {
                            log.warn("Failure loading public suffix list from default resource", ex);
                        }// w w  w . j ava  2  s  . co m
                    }
                } else {
                    DEFAULT_INSTANCE = new PublicSuffixMatcher(Arrays.asList("com"), null);
                }
            }
        }
    }
    return DEFAULT_INSTANCE;
}

From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java

public static boolean repairVersionMatchAttribute(Element element, String attributeName, Log logger) {
    String versionString = getStringAttribute(element, attributeName);
    if (versionString == null) {
        return false;
    }/*from  w  ww .  j  a v a 2 s .com*/

    try {
        StdVersionMatch.newInstance(versionString);
    } catch (ParseException ex) {
        logger.warn("Deleting invalid " + attributeName + " string " + versionString, ex);
        element.removeAttribute(attributeName);
        return true;
    }

    return false;
}

From source file:org.apache.tajo.util.StringUtils.java

/**
 * Print a log message for starting up and shutting down
 * @param clazz the class of the server/* www. j a  v a2  s  . com*/
 * @param args arguments
 * @param LOG the target log object
 */
public static void startupShutdownMessage(Class<?> clazz, String[] args,
        final org.apache.commons.logging.Log LOG) {
    final String hostname = org.apache.hadoop.net.NetUtils.getHostname();
    final String classname = clazz.getSimpleName();
    LOG.info(toStartupShutdownString("STARTUP_MSG: ",
            new String[] { "Starting " + classname, "  host = " + hostname, "  args = " + Arrays.asList(args),
                    "  version = " + org.apache.tajo.util.VersionInfo.getVersion(),
                    "  classpath = " + System.getProperty("java.class.path"),
                    "  build = " + org.apache.tajo.util.VersionInfo.getUrl() + " -r "
                            + org.apache.tajo.util.VersionInfo.getRevision() + "; compiled by '"
                            + org.apache.tajo.util.VersionInfo.getUser() + "' on "
                            + org.apache.tajo.util.VersionInfo.getDate(),
                    "  java = " + System.getProperty("java.version") }));

    if (SystemUtils.IS_OS_UNIX) {
        try {
            SignalLogger.INSTANCE.register(LOG);
        } catch (Throwable t) {
            LOG.warn("failed to register any UNIX signal loggers: ", t);
        }
    }
    ShutdownHookManager.get().addShutdownHook(new Runnable() {
        @Override
        public void run() {
            LOG.info(toStartupShutdownString("SHUTDOWN_MSG: ",
                    new String[] { "Shutting down " + classname + " at " + hostname }));
        }
    }, SHUTDOWN_HOOK_PRIORITY);
}

From source file:org.danann.cernunnos.runtime.Main.java

public static void main(String[] args) {

    Log log = LogFactory.getLog(ScriptRunner.class);

    // Put some whitespace between the command and the output...
    System.out.println("");

    // Register custom protocol handlers...
    try {//from   w w  w .j a v  a 2s.  c om
        URL.setURLStreamHandlerFactory(new URLStreamHandlerFactoryImpl());
    } catch (Throwable t) {
        log.warn("Cernunnos was unable to register a URLStreamHandlerFactory.  "
                + "Custom URL protocols may not work properly (e.g. classpath://, c:/).  "
                + "See stack trace below.", t);
    }

    // Establish CRN_HOME...
    String crnHome = System.getenv("CRN_HOME");
    if (crnHome == null) {
        if (log.isDebugEnabled()) {
            log.debug("The CRN_HOME environment variable is not defined;  "
                    + "this is completely normal for embedded applications " + "of Cernunnos.");
        }
    }

    // Look at the specified script:  might it be in the bin/ directory?
    String location = args[0];
    try {
        // This is how ScriptRunner will attempt to locate the script file...
        URL u = new URL(new File(".").toURI().toURL(), location);
        if (u.getProtocol().equals("file")) {
            // We know the specified resource is a local file;  is it either 
            // (1) absolute or (2) relative to the directory where Java is 
            // executing?
            if (!new File(u.toURI()).exists() && crnHome != null) {
                // No.  And what's more, 'CRN_HOME' is defined.  In this case 
                // let's see if the specified script *is* present in the bin/ 
                // directory.
                StringBuilder path = new StringBuilder();
                path.append(crnHome).append(File.separator).append("bin").append(File.separator)
                        .append(location);
                File f = new File(path.toString());
                if (f.exists()) {
                    // The user is specifying a Cernunnos script in the bin/ directory...
                    location = f.toURI().toURL().toExternalForm();
                    if (log.isInfoEnabled()) {
                        log.info("Resolving the specified Cernunnos document "
                                + "to a file in the CRN_HOME/bin directory:  " + location);
                    }
                }
            }
        }
    } catch (Throwable t) {
        // Just let this pass -- genuine issues will be caught & reported shortly...
    }

    // Analyze the command-line arguments...
    RuntimeRequestResponse req = new RuntimeRequestResponse();
    switch (args.length) {
    case 0:
        // No file provided, can't continue...
        System.out.println("Usage:\n\n\t>crn [script_name] [arguments]");
        System.exit(0);
        break;
    default:
        for (int i = 1; i < args.length; i++) {
            req.setAttribute("$" + i, args[i]);
        }
        break;
    }

    ScriptRunner runner = new ScriptRunner();
    runner.run(location, req);

}