Example usage for org.apache.commons.logging LogFactory getFactory

List of usage examples for org.apache.commons.logging LogFactory getFactory

Introduction

In this page you can find the example usage for org.apache.commons.logging LogFactory getFactory.

Prototype

@Deprecated
public static LogFactory getFactory() 

Source Link

Document

This method only exists for compatibility with unusual Commons Logging API usage like e.g.

Usage

From source file:org.apache.oozie.service.TestXLogService.java

@Override
protected void tearDown() throws Exception {
    LogFactory.getFactory().release();
    LogManager.resetConfiguration();
    super.tearDown();
}

From source file:org.apache.parquet.cli.Main.java

public static void main(String[] args) throws Exception {
    // reconfigure logging with the kite CLI configuration
    PropertyConfigurator.configure(Main.class.getResource("/cli-logging.properties"));
    Logger console = LoggerFactory.getLogger(Main.class);
    // use Log4j for any libraries using commons-logging
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.Log4JLogger");
    int rc = ToolRunner.run(new Configuration(), new Main(console), args);
    System.exit(rc);/*from  www . j a v  a 2s  . c  om*/
}

From source file:org.apache.portals.pluto.test.utilities.SimpleTestDriver.java

/**
 * @throws java.lang.Exception//  ww w .j a v  a 2  s. c  o  m
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {

    if (driver == null) {
        loginUrl = System.getProperty("test.server.login.url");
        host = System.getProperty("test.server.host");
        port = System.getProperty("test.server.port");
        username = System.getProperty("test.server.username");
        usernameId = System.getProperty("test.server.username.id");
        password = System.getProperty("test.server.password");
        passwordId = System.getProperty("test.server.password.id");
        browser = System.getProperty("test.browser");
        testContextBase = System.getProperty("test.context.base");
        StringBuilder sb = new StringBuilder();
        sb.append("http://");
        sb.append(host);
        if (port != null && !port.isEmpty()) {
            sb.append(":");
            sb.append(port);
        }
        sb.append("/");
        sb.append(testContextBase);
        baseUrl = sb.toString();
        String str = System.getProperty("test.url.strategy");
        useGeneratedUrl = str.equalsIgnoreCase("generateURLs");
        str = System.getProperty("test.debug");
        debug = str.equalsIgnoreCase("true");
        str = System.getProperty("test.timeout");
        dryrun = Boolean.valueOf(System.getProperty("test.dryrun"));
        timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str) : 3;
        String wd = System.getProperty("test.browser.webDriver");
        String binary = System.getProperty("test.browser.binary");
        String headlessProperty = System.getProperty("test.browser.headless");
        boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0)
                || Boolean.valueOf(headlessProperty)));
        String maximizedProperty = System.getProperty("test.browser.maximized");
        boolean maximized = Boolean.valueOf(maximizedProperty);

        System.out.println("before class.");
        System.out.println("   Debug        =" + debug);
        System.out.println("   Dryrun       =" + dryrun);
        System.out.println("   Timeout      =" + timeout);
        System.out.println("   Login URL    =" + loginUrl);
        System.out.println("   Host         =" + host);
        System.out.println("   Port         =" + port);
        System.out.println("   Context      =" + testContextBase);
        System.out.println("   Generate URL =" + useGeneratedUrl);
        System.out.println("   Username     =" + username);
        System.out.println("   UsernameId   =" + usernameId);
        System.out.println("   Password     =" + password);
        System.out.println("   PasswordId   =" + passwordId);
        System.out.println("   Browser      =" + browser);
        System.out.println("   Driver       =" + wd);
        System.out.println("   binary       =" + binary);
        System.out.println("   headless     =" + headless);
        System.out.println("   maximized    =" + maximized);

        if (browser.equalsIgnoreCase("firefox")) {

            System.setProperty("webdriver.gecko.driver", wd);
            FirefoxOptions options = new FirefoxOptions();
            options.setLegacy(true);
            options.setAcceptInsecureCerts(true);

            if ((binary != null) && (binary.length() != 0)) {
                options.setBinary(binary);
            }

            if (headless) {
                options.setHeadless(true);
            }

            driver = new FirefoxDriver(options);

        } else if (browser.equalsIgnoreCase("internetExplorer")) {
            System.setProperty("webdriver.ie.driver", wd);
            driver = new InternetExplorerDriver();
        } else if (browser.equalsIgnoreCase("chrome")) {

            System.setProperty("webdriver.chrome.driver", wd);
            ChromeOptions options = new ChromeOptions();

            if ((binary != null) && (binary.length() > 0)) {
                options.setBinary(binary);
            }

            if (headless) {
                options.addArguments("--headless");
            }

            options.addArguments("--disable-infobars");
            options.setAcceptInsecureCerts(true);

            if (maximized) {
                // The webDriver.manage().window().maximize() feature does not work correctly in headless mode, so set the
                // window size to 1920x1200 (resolution of a 15.4 inch screen).
                options.addArguments("--window-size=1920,1200");
            }

            driver = new ChromeDriver(options);

        } else if (browser.equalsIgnoreCase("phantomjs")) {
            DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
            capabilities.setJavascriptEnabled(true);
            capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary);
            driver = new PhantomJSDriver(capabilities);
        } else if (browser.equalsIgnoreCase("htmlUnit")) {
            LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
                    "org.apache.commons.logging.impl.NoOpLog");
            Logger.getLogger("com.gargoylesoftware").setLevel(Level.SEVERE);
            Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.SEVERE);
            driver = new HtmlUnitDriver() {
                @Override
                protected WebClient getWebClient() {
                    WebClient webClient = super.getWebClient();
                    WebClientOptions options = webClient.getOptions();
                    options.setThrowExceptionOnFailingStatusCode(false);
                    options.setThrowExceptionOnScriptError(false);
                    options.setPrintContentOnFailingStatusCode(false);
                    webClient.setCssErrorHandler(new SilentCssErrorHandler());
                    return webClient;
                }
            };
        } else if (browser.equalsIgnoreCase("safari")) {
            driver = new SafariDriver();
        } else {
            throw new Exception("Unsupported browser: " + browser);
        }

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                driver.quit();
            }
        }));

        if (maximized) {
            driver.manage().window().maximize();
        }

        if (!dryrun) {
            login();
        }
    }
}

From source file:org.apache.tools.ant.listener.CommonsLoggingListener.java

private Log getLog(String cat, String suffix) {
    if (suffix != null) {
        suffix = suffix.replace('.', '-');
        suffix = suffix.replace(' ', '-');
        cat = cat + "." + suffix;
    }// w  w w .ja v a 2 s .c om
    final PrintStream tmpOut = System.out;
    final PrintStream tmpErr = System.err;
    System.setOut(out);
    System.setErr(err);

    if (!initialized) {
        try {
            logFactory = LogFactory.getFactory();
        } catch (final LogConfigurationException e) {
            e.printStackTrace(System.err);
            return null;
        }
    }

    initialized = true;
    final Log log = logFactory.getInstance(cat);
    System.setOut(tmpOut);
    System.setErr(tmpErr);
    return log;
}

From source file:org.docx4j.fonts.fop.fonts.apps.TTFReader.java

/**
 * The main method for the TTFReader tool.
 *
 * @param  args Command-line arguments: [options] fontfile.ttf xmlfile.xml
 * where options can be:/* w w  w .ja va2  s.com*/
 * -fn <fontname>
 * default is to use the fontname in the .ttf file, but you can override
 * that name to make sure that the embedded font is used instead of installed
 * fonts when viewing documents with Acrobat Reader.
 * -cn <classname>
 * default is to use the fontname
 * -ef <path to the truetype fontfile>
 * will add the possibility to embed the font. When running fop, fop will look
 * for this file to embed it
 * -er <path to truetype fontfile relative to org/apache/fop/render/pdf/fonts>
 * you can also include the fontfile in the fop.jar file when building fop.
 * You can use both -ef and -er. The file specified in -ef will be searched first,
 * then the -er file.
 */
public static void main(String[] args) {
    String embFile = null;
    String embResource = null;
    String className = null;
    String fontName = null;
    String ttcName = null;
    boolean isCid = true;

    Map options = new java.util.HashMap();
    String[] arguments = parseArguments(options, args);

    // Enable the simple command line logging when no other logger is
    // defined.
    LogFactory logFactory = LogFactory.getFactory();
    if (System.getProperty("org.apache.commons.logging.Log") == null) {
        logFactory.setAttribute("org.apache.commons.logging.Log", CommandLineLogger.class.getName());
    }

    determineLogLevel(options);

    TTFReader app = new TTFReader();

    log.info("TTF Reader for Apache FOP " + Version.getVersion() + "\n");

    if (options.get("-enc") != null) {
        String enc = (String) options.get("-enc");
        if ("ansi".equals(enc)) {
            isCid = false;
        }
    }

    if (options.get("-ttcname") != null) {
        ttcName = (String) options.get("-ttcname");
    }

    if (options.get("-ef") != null) {
        embFile = (String) options.get("-ef");
    }

    if (options.get("-er") != null) {
        embResource = (String) options.get("-er");
    }

    if (options.get("-fn") != null) {
        fontName = (String) options.get("-fn");
    }

    if (options.get("-cn") != null) {
        className = (String) options.get("-cn");
    }

    if (arguments.length != 2 || options.get("-h") != null || options.get("-help") != null
            || options.get("--help") != null) {
        displayUsage();
    } else {
        try {
            log.info("Parsing font...");
            TTFFile ttf = app.loadTTF(arguments[0], ttcName);
            if (ttf != null) {
                org.w3c.dom.Document doc = app.constructFontXML(ttf, fontName, className, embResource, embFile,
                        isCid, ttcName);

                if (isCid) {
                    log.info("Creating CID encoded metrics...");
                } else {
                    log.info("Creating WinAnsi encoded metrics...");
                }

                if (doc != null) {
                    app.writeFontXML(doc, arguments[1]);
                }

                if (ttf.isEmbeddable()) {
                    log.info("This font contains no embedding license restrictions.");
                } else {
                    log.info("** Note: This font contains license retrictions for\n"
                            + "         embedding. This font shouldn't be embedded.");
                }
            }
            log.info("");
            log.info("XML font metrics file successfully created.");
        } catch (Exception e) {
            log.error("Error while building XML font metrics file.", e);
            System.exit(-1);
        }
    }
}

From source file:org.eclipse.smila.utils.test.TestExtensions.java

/**
 * {@inheritDoc}/*from   w w w  .  jav a 2s. c o  m*/
 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    // to increase coverage
    LogFactory.getFactory().setAttribute("log4j.logger.org.eclipse.smila", "TRACE, file");
}

From source file:org.floggy.synchronization.jme.maven.SynchronizationMojo.java

/**
* DOCUMENT ME!/*  ww w  .  ja  v a 2 s  .  c o m*/
*
* @throws MojoExecutionException DOCUMENT ME!
*/
public void execute() throws MojoExecutionException {
    MavenLogWrapper.setLog(getLog());

    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "net.sourceforge.floggy.maven.MavenLogWrapper");

    Weaver weaver = new Weaver();

    try {
        List list = project.getCompileClasspathElements();
        File temp = new File(project.getBuild().getDirectory(), String.valueOf(System.currentTimeMillis()));
        FileUtils.forceMkdir(temp);
        weaver.setOutputFile(temp);
        weaver.setInputFile(input);
        weaver.setClasspath((String[]) list.toArray(new String[list.size()]));

        if (configurationFile == null) {
            Configuration configuration = new Configuration();
            configuration.setGenerateSource(generateSource);
            weaver.setConfiguration(configuration);
        } else {
            weaver.setConfigurationFile(configurationFile);
        }

        weaver.execute();
        FileUtils.copyDirectory(temp, output);
        FileUtils.forceDelete(temp);
    } catch (Exception e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:org.floggy.synchronization.jme.weaver.WeaverTask.java

/**
* DOCUMENT ME!//ww  w . ja v  a2s.co m
*
* @throws BuildException DOCUMENT ME!
*/
public void execute() throws BuildException {
    AntLog.setTask(this);
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", AntLog.class.getName());

    Weaver weaver = new Weaver();

    try {
        weaver.setClasspath(classpath.list());
        weaver.setInputFile(input);
        weaver.setOutputFile(output);

        if (configurationFile == null) {
            Configuration configuration = new Configuration();
            configuration.setGenerateSource(generateSource);
            weaver.setConfiguration(configuration);
        } else {
            weaver.setConfigurationFile(configurationFile);
        }

        weaver.execute();
    } catch (Exception e) {
        throw new BuildException(e);
    }
}

From source file:org.kitesdk.cli.Main.java

public static void main(String[] args) throws Exception {
    // reconfigure logging with the kite CLI configuration
    PropertyConfigurator.configure(Main.class.getResource("/kite-cli-logging.properties"));
    Logger console = LoggerFactory.getLogger(Main.class);
    // use Log4j for any libraries using commons-logging
    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.Log4JLogger");
    int rc = ToolRunner.run(new HiveConf(), new Main(console), args);
    System.exit(rc);/*from   ww  w.jav  a2s.c  om*/
}

From source file:org.qedeq.base.trace.Trace.java

/**
 * Is debug log currently enabled?/*from  ww  w .  ja v  a  2  s .  co m*/
 *
 * @param   tracingClass    Class we want to know the debug logging status for.
 * @return  Debug log enabled.
 */
public static boolean isDebugEnabled(final Class tracingClass) {
    if (traceOn) {
        final Log log = LogFactory.getFactory().getInstance(tracingClass);
        return log.isDebugEnabled();
    }
    return false;
}