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

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

Introduction

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

Prototype

void error(Object message, Throwable t);

Source Link

Document

Logs an error with error log level.

Usage

From source file:com.moss.appsnap.keeper.KeeperMain.java

public static void main(String[] args) throws Throwable {

    BasicConfigurator.resetConfiguration();
    BasicConfigurator.configure();//from   ww w. ja  v  a  2  s .  com

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

    try {
        new Keeper(new Url(args[0]));
    } catch (Throwable e) {
        log.error("Error launching keeper: " + e.getMessage(), e);
        throw e;
    }
}

From source file:com.microsoft.tfs.client.clc.vc.Main.java

public static void main(final String[] args) {
    TELoggingConfiguration.configure();/*from   w  w  w  . j a v  a2s .co m*/

    final Log log = LogFactory.getLog(Main.class);
    log.debug("Entering Main"); //$NON-NLS-1$
    Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread t, final Throwable e) {
            log.error("Unhandled exception in the thread " + t.getName() + " : ", e); //$NON-NLS-1$ //$NON-NLS-2$
            /*
             * Let the shutdown manager clean up any registered items.
             */
            try {
                log.debug("Shutting down"); //$NON-NLS-1$
                ShutdownManager.getInstance().shutdown();
                log.debug("Has shut down"); //$NON-NLS-1$
            } catch (final Exception ex) {
                log.error("Unhandled exception during shutdown: ", ex); //$NON-NLS-1$
            }
        }
    });
    /*
     * Please don't do any fancy work in this method, because we have a CLC
     * test harness that calls Main.run() directly, and we can't test
     * functionality in this method (because this method can't return a
     * status code but exits the process directly, which kind of hoses any
     * test framework).
     */

    final Main main = new Main();
    int ret = ExitCode.FAILURE;

    try {
        ret = main.run(args);
    } catch (final Throwable e) {
        log.error("Unhandled exception reached Main: ", e); //$NON-NLS-1$
    } finally {
        /*
         * Let the shutdown manager clean up any registered items.
         */
        try {
            log.info("Shutting down"); //$NON-NLS-1$
            ShutdownManager.getInstance().shutdown();
            log.info("Has shut down"); //$NON-NLS-1$
        } catch (final Exception e) {
            log.error("Unhandled exception during shutdown: ", e); //$NON-NLS-1$
        }
    }

    System.exit(ret);
}

From source file:com.morty.podcast.writer.validation.StandardFileValidator.java

public static void main(String[] args) {
    //Process a directory without exclusion...
    Log m_logger = LogFactory.getLog(StandardFileValidator.class);
    m_logger.info("Starting Validator");

    if (args.length != 1)
        throw new NullPointerException("No directory specified");

    String fileToProcess = args[0];
    m_logger.info("Processing [" + fileToProcess + "]");
    StandardFileValidator sfv = new StandardFileValidator();
    sfv.setFolderToProcess(new File(fileToProcess));
    try {/*from w  w  w  . ja va2 s  .  co m*/
        sfv.process();
        m_logger.info("Directory Valid");
    } catch (Exception ex) {
        m_logger.info("Directory InValid");
        m_logger.error("Error thrown", ex);
    }

    m_logger.info("Finished Validator");
}

From source file:net.sf.mcf2pdf.Main.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    Options options = new Options();

    Option o = OptionBuilder.hasArg().isRequired()
            .withDescription("Installation location of My CEWE Photobook. REQUIRED.").create('i');
    options.addOption(o);//from   w w w  . ja  v a2  s.  c o  m
    options.addOption("h", false, "Prints this help and exits.");
    options.addOption("t", true, "Location of MCF temporary files.");
    options.addOption("w", true, "Location for temporary images generated during conversion.");
    options.addOption("r", true, "Sets the resolution to use for page rendering, in DPI. Default is 150.");
    options.addOption("n", true, "Sets the page number to render up to. Default renders all pages.");
    options.addOption("b", false, "Prevents rendering of binding between double pages.");
    options.addOption("x", false, "Generates only XSL-FO content instead of PDF content.");
    options.addOption("q", false, "Quiet mode - only errors are logged.");
    options.addOption("d", false, "Enables debugging logging output.");

    CommandLine cl;
    try {
        CommandLineParser parser = new PosixParser();
        cl = parser.parse(options, args);
    } catch (ParseException pe) {
        printUsage(options, pe);
        System.exit(3);
        return;
    }

    if (cl.hasOption("h")) {
        printUsage(options, null);
        return;
    }

    if (cl.getArgs().length != 2) {
        printUsage(options,
                new ParseException("INFILE and OUTFILE must be specified. Arguments were: " + cl.getArgList()));
        System.exit(3);
        return;
    }

    File installDir = new File(cl.getOptionValue("i"));
    if (!installDir.isDirectory()) {
        printUsage(options, new ParseException("Specified installation directory does not exist."));
        System.exit(3);
        return;
    }

    File tempDir = null;
    String sTempDir = cl.getOptionValue("t");
    if (sTempDir == null) {
        tempDir = new File(new File(System.getProperty("user.home")), ".mcf");
        if (!tempDir.isDirectory()) {
            printUsage(options, new ParseException("MCF temporary location not specified and default location "
                    + tempDir + " does not exist."));
            System.exit(3);
            return;
        }
    } else {
        tempDir = new File(sTempDir);
        if (!tempDir.isDirectory()) {
            printUsage(options, new ParseException("Specified temporary location does not exist."));
            System.exit(3);
            return;
        }
    }

    File mcfFile = new File(cl.getArgs()[0]);
    if (!mcfFile.isFile()) {
        printUsage(options, new ParseException("MCF input file does not exist."));
        System.exit(3);
        return;
    }
    mcfFile = mcfFile.getAbsoluteFile();

    File tempImages = new File(new File(System.getProperty("user.home")), ".mcf2pdf");
    if (cl.hasOption("w")) {
        tempImages = new File(cl.getOptionValue("w"));
        if (!tempImages.mkdirs() && !tempImages.isDirectory()) {
            printUsage(options,
                    new ParseException("Specified working dir does not exist and could not be created."));
            System.exit(3);
            return;
        }
    }

    int dpi = 150;
    if (cl.hasOption("r")) {
        try {
            dpi = Integer.valueOf(cl.getOptionValue("r")).intValue();
            if (dpi < 30 || dpi > 600)
                throw new IllegalArgumentException();
        } catch (Exception e) {
            printUsage(options,
                    new ParseException("Parameter for option -r must be an integer between 30 and 600."));
        }
    }

    int maxPageNo = -1;
    if (cl.hasOption("n")) {
        try {
            maxPageNo = Integer.valueOf(cl.getOptionValue("n")).intValue();
            if (maxPageNo < 0)
                throw new IllegalArgumentException();
        } catch (Exception e) {
            printUsage(options, new ParseException("Parameter for option -n must be an integer >= 0."));
        }
    }

    boolean binding = true;
    if (cl.hasOption("b")) {
        binding = false;
    }

    OutputStream finalOut;
    if (cl.getArgs()[1].equals("-"))
        finalOut = System.out;
    else {
        try {
            finalOut = new FileOutputStream(cl.getArgs()[1]);
        } catch (IOException e) {
            printUsage(options, new ParseException("Output file could not be created."));
            System.exit(3);
            return;
        }
    }

    // configure logging, if no system property is present
    if (System.getProperty("log4j.configuration") == null) {
        PropertyConfigurator.configure(Main.class.getClassLoader().getResource("log4j.properties"));

        Logger.getRootLogger().setLevel(Level.INFO);
        if (cl.hasOption("q"))
            Logger.getRootLogger().setLevel(Level.ERROR);
        if (cl.hasOption("d"))
            Logger.getRootLogger().setLevel(Level.DEBUG);
    }

    // start conversion to XSL-FO
    // if -x is specified, this is the only thing we do
    OutputStream xslFoOut;
    if (cl.hasOption("x"))
        xslFoOut = finalOut;
    else
        xslFoOut = new ByteArrayOutputStream();

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

    try {
        new Mcf2FoConverter(installDir, tempDir, tempImages).convert(mcfFile, xslFoOut, dpi, binding,
                maxPageNo);
        xslFoOut.flush();

        if (!cl.hasOption("x")) {
            // convert to PDF
            log.debug("Converting XSL-FO data to PDF");
            byte[] data = ((ByteArrayOutputStream) xslFoOut).toByteArray();
            PdfUtil.convertFO2PDF(new ByteArrayInputStream(data), finalOut, dpi);
            finalOut.flush();
        }
    } catch (Exception e) {
        log.error("An exception has occured", e);
        System.exit(1);
        return;
    } finally {
        if (finalOut instanceof FileOutputStream) {
            try {
                finalOut.close();
            } catch (Exception e) {
            }
        }
    }
}

From source file:com.microsoft.gittf.client.clc.Main.java

public static void main(String[] args) {
    // Configure logging, use the standard TFS SDK logging.
    System.setProperty("teamexplorer.application", ProductInformation.getProductName()); //$NON-NLS-1$
    LoggingConfiguration.configure();/*from w w w.  j a  va  2  s  .com*/

    final Log log = LogFactory.getLog(ProductInformation.getProductName());

    try {
        ArgumentCollection mainArguments = new ArgumentCollection();

        try {
            mainArguments = ArgumentParser.parse(args, ARGUMENTS,
                    ArgumentParserOptions.ALLOW_UNKNOWN_ARGUMENTS);
        } catch (ArgumentParserException e) {
            console.getErrorStream().println(e.getLocalizedMessage());
            console.getErrorStream().println(getUsage());
            System.exit(ExitCode.FAILURE);
        }

        if (mainArguments.contains("version")) //$NON-NLS-1$
        {
            console.getOutputStream().println(Messages.formatString("Main.ApplicationVersionFormat", //$NON-NLS-1$
                    ProductInformation.getProductName(), ProductInformation.getBuildNumber()));

            return;
        }

        /*
         * Special case "--help command" handling - convert to
         * "help command"
         */
        if (mainArguments.contains("help") && mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$
        {
            HelpCommand helpCommand = new HelpCommand();
            helpCommand.setArguments(ArgumentParser.parse(new String[] {
                    ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues()[0] //$NON-NLS-1$                
            }, helpCommand.getPossibleArguments()));

            helpCommand.setConsole(console);
            helpCommand.run();
            return;
        } else if (mainArguments.contains("help") || !mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$
        {
            showHelp();
            return;
        }

        // Set the verbosity of the console from the arguments.
        if (mainArguments.contains("quiet")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.QUIET);
        } else if (mainArguments.contains("verbose")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.VERBOSE);
        }

        /*
         * Parse the free arguments into the command name and arguments to
         * pass to it. Add any unmatched arguments that were specified on
         * the command line before the argument. (eg, for
         * "git-tf --bare clone", we parsed the "--bare" as an unmatched
         * argument to the main command. We instead want to add the "--bare"
         * as an argument to "clone".)
         */
        String[] fullCommand = ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues(); //$NON-NLS-1$
        String[] additionalArguments = mainArguments.getUnknownArguments();

        String commandName = fullCommand[0];
        String[] commandArgs = new String[additionalArguments.length + (fullCommand.length - 1)];

        if (additionalArguments.length > 0) {
            System.arraycopy(additionalArguments, 0, commandArgs, 0, additionalArguments.length);
        }

        if (fullCommand.length > 1) {
            System.arraycopy(fullCommand, 1, commandArgs, mainArguments.getUnknownArguments().length,
                    fullCommand.length - 1);
        }

        // Locate the specified command by name
        List<CommandDefinition> possibleCommands = new ArrayList<CommandDefinition>();

        for (CommandDefinition c : COMMANDS) {
            if (c.getName().equals(commandName)) {
                possibleCommands.clear();
                possibleCommands.add(c);
                break;
            } else if (c.getName().startsWith(commandName)) {
                possibleCommands.add(c);
            }
        }

        if (possibleCommands.size() == 0) {
            printError(Messages.formatString("Main.CommandNotFoundFormat", commandName, //$NON-NLS-1$
                    ProductInformation.getProductName()));
            System.exit(1);
        }

        if (possibleCommands.size() > 1) {
            printError(Messages.formatString("Main.AmbiguousCommandFormat", commandName, //$NON-NLS-1$
                    ProductInformation.getProductName()));

            for (CommandDefinition c : possibleCommands) {
                printError(Messages.formatString("Main.AmbiguousCommandListFormat", c.getName()), false); //$NON-NLS-1$
            }

            System.exit(1);
        }

        // Instantiate the command
        final CommandDefinition commandDefinition = possibleCommands.get(0);
        Command command = null;

        try {
            command = commandDefinition.getType().newInstance();
        } catch (Exception e) {
            printError(Messages.formatString("Main.CommandCreationFailedFormat", commandName)); //$NON-NLS-1$
            System.exit(1);
        }

        // Set the console
        command.setConsole(console);

        // Parse the arguments
        ArgumentCollection argumentCollection = null;

        try {
            argumentCollection = ArgumentParser.parse(commandArgs, command.getPossibleArguments());
        } catch (ArgumentParserException e) {
            Main.printError(e.getLocalizedMessage());
            Main.printError(getUsage(command));

            log.error("Could not parse arguments", e); //$NON-NLS-1$
            System.exit(1);
        }

        // Handle the --help argument directly
        if (argumentCollection.contains("help")) //$NON-NLS-1$
        {
            command.showHelp();
            System.exit(0);
        }

        // Set the verbosity of the console from the arguments.
        if (argumentCollection.contains("quiet")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.QUIET);
        } else if (argumentCollection.contains("verbose")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.VERBOSE);
        }

        command.setArguments(argumentCollection);

        System.exit(command.run());

    } catch (Exception e) {
        printError(e.getLocalizedMessage());
        log.warn(MessageFormat.format("Error executing command: {0}", getCommandLine(args)), e); //$NON-NLS-1$
    }
}

From source file:com.lfv.lanzius.Main.java

public static void main(String[] args) {

    /*/*from w ww. j a v a  2 s.  c om*/
     * debug levels:
     * error - Runtime errors or unexpected conditions. Expect these to be immediately visible on a status console. See also Internationalization.
     * warn  - Use of deprecated APIs, poor use of API, 'almost' errors, other runtime situations that are undesirable or unexpected, but not necessarily "wrong". Expect these to be immediately visible on a status console. See also Internationalization.
     * info  - Interesting runtime events (startup/shutdown). Expect these to be immediately visible on a console, so be conservative and keep to a minimum. See also Internationalization.
     * debug - detailed information on the flow through the system. Expect these to be written to logs only.
     */

    Log log = null;
    DOMConfigurator conf = new DOMConfigurator();
    DOMConfigurator.configure("data/properties/loggingproperties.xml");
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");

    try {
        if (args.length >= 1) {
            // Help
            if (args[0].startsWith("-h")) {
                printUsage();
                return;
            }
            // List devices
            else if (args[0].startsWith("-l")) {
                AudioTest.listDevices();
                return;
            }
            // Test seleted device
            else if (args[0].startsWith("-d")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "warn");
                try {
                    String option = "all";
                    if (args.length >= 4)
                        option = args[3];

                    if (option.equals("loop:direct"))
                        AudioTest.testDevicesDirect(Integer.parseInt(args[1]), Integer.parseInt(args[2]));
                    else {
                        if (option.indexOf("debug") != -1)
                            System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "debug");

                        AudioTest.testDevices(Integer.parseInt(args[1]), Integer.parseInt(args[2]), option,
                                (args.length >= 5) ? args[4] : null, (args.length >= 6) ? args[5] : null,
                                (args.length >= 7) ? args[6] : null);
                    }
                } catch (Exception ex) {
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println(
                            "  yada.jar -d output_device input_device <option> <jitter_buffer> <output_buffer> <input_buffer>");
                    System.out.println("  option:");
                    System.out.println("    all(default)");
                    System.out.println("    clip");
                    System.out.println("    loop:jspeex");
                    System.out.println("    loop:null");
                    System.out.println("    loop:direct");
                    System.out.println("    loopdebug:jspeex");
                    System.out.println("    loopdebug:null");
                    System.out.println("  jitter_buffer:");
                    System.out.println("    size of jitter buffer in packets (1-20)");
                    System.out.println("  output_buffer:");
                    System.out.println("    size of output buffer in packets (1.0-4.0)");
                    System.out.println("  input_buffer:");
                    System.out.println("    size of input buffer in packets (1.0-4.0)");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                //System.out.println("Exiting...");
                return;
            } else if (args[0].startsWith("-m")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "warn");
                try {
                    AudioTest.testMicrophoneLevel(Integer.parseInt(args[1]));
                } catch (Exception ex) {
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println("  yada.jar -m input_device");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                return;
            } else if (args[0].startsWith("-s")) {
                Packet.randomSeed = 9182736455L ^ System.currentTimeMillis();
                if (args.length > 2 && args[1].startsWith("-configuration")) {
                    String configFilename = args[2];
                    if (args.length > 4 && args[3].startsWith("-exercise")) {
                        String exerciseFilename = args[4];

                        LanziusServer.start(configFilename, exerciseFilename);
                    } else {
                        LanziusServer.start(configFilename);
                    }
                } else {
                    LanziusServer.start();
                }
                return;
            } else if (args[0].startsWith("-f")) {
                System.setProperty("org.apache.commons.logging.Log",
                        "org.apache.commons.logging.impl.SimpleLog");
                System.setProperty(
                        "org.apache.commons.logging.simplelog.log.com.lfv.lanzius.application.FootSwitchController",
                        "debug");
                try {
                    System.out.println("Starting footswitch controller test using device " + args[1]);
                    try {
                        boolean inverted = false;
                        if (args.length >= 3)
                            inverted = args[2].toLowerCase().startsWith("inv");
                        FootSwitchController c = new FootSwitchController(null, args[1],
                                Constants.PERIOD_FTSW_CONNECTED, inverted);
                        c.start();
                        Thread.sleep(30000);
                    } catch (UnsatisfiedLinkError err) {
                        if (args.length > 1)
                            System.out.println("UnsatisfiedLinkError: " + err.getMessage());
                        else
                            throw new ArrayIndexOutOfBoundsException();
                        System.out.println("Missing ftsw library (ftsw.dll or libftsw.so)");
                        if (!args[1].equalsIgnoreCase("ftdi"))
                            System.out
                                    .println("Missing rxtxSerial library (rxtxSerial.dll or librxtxSerial.so)");
                        if (AudioTest.showStackTrace)
                            err.printStackTrace();
                    }
                } catch (Exception ex) {
                    if (ex instanceof NoSuchPortException)
                        System.out.println("The serial port " + args[1] + " does not exist!");
                    else if (ex instanceof PortInUseException)
                        System.out.println("The serial port " + args[1] + " is already in use!");
                    System.out.println();
                    System.out.println(Config.VERSION);
                    System.out.println();
                    System.out.println("Usage:");
                    System.out.println("  yada.jar -f interface <invert>");
                    System.out.println("  interface:");
                    System.out.println("    ftdi");
                    System.out.println("    comport (COMx or /dev/ttyx)");
                    System.out.println("  invert:");
                    System.out.println("    true");
                    System.out.println("    false (default)");
                    System.out.println();
                    if (AudioTest.showStackTrace && !(ex instanceof ArrayIndexOutOfBoundsException))
                        ex.printStackTrace();
                }
                return;
            } else if (args[0].startsWith("-c")) {
                Packet.randomSeed = 7233103157L ^ System.currentTimeMillis();
                if (args.length >= 2) {
                    try {
                        int id = Integer.valueOf(args[1]);
                        if (id <= 0)
                            throw new NumberFormatException();
                        Controller c = Controller.getInstance();
                        if (args.length >= 3) {
                            if (args[2].equalsIgnoreCase("test")) {
                                c.setAutoTester(true);
                            }
                        }
                        c.init(id);
                        return;
                    } catch (NumberFormatException ex) {
                        printUsage();
                    }
                } else {
                    Controller.getInstance().init(0);
                }
            } else
                printUsage();
        } else
            printUsage();
    } catch (Throwable t) {
        if (log == null)
            log = LogFactory.getLog(Main.class);
        log.error("Unhandled exception or error", t);
    }
}

From source file:com.wavemaker.runtime.data.util.LoggingUtils.java

public static void logCannotRollbackTx(Log logger, Throwable th) {
    logger.error(MessageResource.CANNOT_ROLLBACK_TX.getMessage(), th);
}

From source file:com.dalabs.droop.util.LoggingUtils.java

public static void logAll(Log log, String message, SQLException e) {
    log.error(message == null ? "Top level exception: " : message, e);
    e = e.getNextException();/*www .j a  v  a2 s  . co  m*/
    int indx = 1;
    while (e != null) {
        log.error("Chained exception " + indx + ": ", e);
        e = e.getNextException();
        indx++;
    }
}

From source file:com.ngdata.sep.util.io.Closer.java

/**
 * Closes anything {@link Closeable}, catches any throwable that might occur during closing and logs it as an error.
 *///from w ww.ja v a  2s .c  o m
public static void close(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (Throwable t) {
            Log log = LogFactory.getLog(Closer.class);
            log.error("Error closing object of type " + closeable.getClass().getName(), t);
        }
    }
}

From source file:net.sf.nmedit.jpatch.clavia.nordmodular.NM1ModuleDescriptions.java

public static NM1ModuleDescriptions parse(ClassLoader loader, InputStream stream)
        throws ParserConfigurationException, SAXException, IOException {
    NM1ModuleDescriptions mod = new NM1ModuleDescriptions(loader);

    try {/*  ww  w . j  a v a2s . c  om*/
        ModuleDescriptionsParser.parse(mod, stream);
    } catch (SAXParseException spe) {
        Log log = LogFactory.getLog(NM1ModuleDescriptions.class);
        if (log.isErrorEnabled()) {
            log.error("error in parse(" + loader + "," + stream + "); " + "@" + spe.getLineNumber() + ":"
                    + spe.getColumnNumber(), spe);
        }
    }
    return mod;
}