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

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

Introduction

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

Prototype

public static Log getLog(String name) 

Source Link

Document

Convenience method to return a named logger.

Usage

From source file:com.qrmedia.commons.aspect.example.AdviceDemo.java

public static void main(String[] args) {
    Log log = LogFactory.getLog(AdviceDemo.class);

    AdvisedObject advisedObject = (AdvisedObject) new ClassPathXmlApplicationContext(CONTEXT_FILENAMES)
            .getBean("advisedBean");

    log.info("Calling a traced method...");
    advisedObject.tracedMethod("James Bond", 7, "License to Kill".getBytes());
    log.info("Calling a traced method that returns a result...");
    log.info("Result: " + advisedObject.resultReturningTracedMethod(6));
    log.info("Calling a profiled method...");
    advisedObject.profiledMethod();/*from  w w w .  j  ava 2 s.  c  o m*/
}

From source file:com.alibaba.stonelab.javalab.misc.Misc2.java

public static void main(String[] args) throws Exception {
    Log LOG = LogFactory.getLog(Misc2.class);

    MDC.put("ip", "127.0.0.1");
    MDC.put("user", "stone2083");

    LOG.error("OK");
    MDC.remove("ip");
    MDC.remove("user");
}

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

public static void main(final String[] args) {
    TELoggingConfiguration.configure();// w  w  w  .  ja  v  a  2  s  . 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.sazneo.export.formatter.Main.java

public static void main(String... args) {

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

    if (args.length != 3) {
        logger.error("Usage: java Main <stylesheet> <export xml file> <output dir>");
        System.exit(1);/*from   www .java  2 s  .co  m*/
    }

    String styleSheetPath = args[0];
    File styleSheet = new File(styleSheetPath);

    String exportXmlPath = args[1];
    File exportXml = new File(exportXmlPath);

    String outPutDirPath = args[2];
    File outputDir = new File(outPutDirPath);
    if (!outputDir.exists()) {
        outputDir.mkdirs();
    }

    try {
        File outputFile = new File(outputDir, "export.html");
        FileOutputStream outputStream = new FileOutputStream(outputFile);
        HtmlFormatter formatter = new HtmlFormatter(styleSheet, exportXml, outputStream);
        formatter.transform();
        FileProcessor fileProcessor = new FileProcessor(exportXml, outputDir);
        fileProcessor.process();

    } catch (IOException e) {
        logger.error(MessageFormat.format("Failed to create export.html at {0}:\n {1}", outPutDirPath, e));
    }
}

From source file:LoggingTrial.java

public static void main(String[] args) {
    Log log = LogFactory.getLog(LoggingTrial.class);
    System.out.println("The Log being used >>> " + log);

    Exception e = new Exception("A DUMMY EXCEPTION");
    if (log.isTraceEnabled()) {
        log.trace("TRACE TEST");
        log.trace("TRACE TEST", e);
    }/*from www.  j  a v a2s  . com*/
    if (log.isDebugEnabled()) {
        log.debug("DEBUG TEST");
        log.debug("DEBUG TEST", e);
    }

    if (log.isInfoEnabled()) {
        log.info("INFO TEST");
        log.info("INFO TEST", e);
    }
    if (log.isWarnEnabled()) {
        log.warn("WARN TEST");
        log.warn("WARN TEST", e);
    }

    if (log.isErrorEnabled()) {
        log.error("ERROR TEST");
        log.error("ERROR TEST", e);
    }

    if (log.isFatalEnabled()) {
        log.fatal("FATAL TEST");
        log.fatal("FATAL TEST", e);
    }
}

From source file:com.microsoft.tfs.sdk.samples.console.LogConfigurationSample.java

public static void main(final String[] args) throws InterruptedException {
    /*/*from  ww  w . ja  v a 2 s.  c  o  m*/
     * Use Apache Commons Logging to get a logger for test purposes. All TEE
     * SDK classes obtain loggers this way.
     */

    final Log log = LogFactory.getLog(LogConfigurationSample.class);

    /*
     * Log once using the default TFS SDK for Java log4j configuration,
     * which is usually the log4j.properties resource contained in the TEE
     * SDK JAR (but may be another configuration file found first on the
     * classpath by log4j).
     */

    logAllLevels(log, "default TFS SDK for Java log configuration"); //$NON-NLS-1$

    /*
     * Configure with a resource from this sample project to show TRACE and
     * above (most verbose).
     */

    Config.configure(new ClassloaderConfigurationProvider(LogConfigurationSample.class.getClassLoader(),
            new String[] { "com/microsoft/tfs/sdk/samples/console/log4j-trace.properties" //$NON-NLS-1$
            }), EnableReconfigurationPolicy.DISABLE_WHEN_EXTERNALLY_CONFIGURED,
            ResetConfigurationPolicy.RESET_EXISTING);

    logAllLevels(log, "TRACE and above shown"); //$NON-NLS-1$

    /*
     * Configure with a resource from this sample project to show WARN and
     * above (less verbose).
     */

    Config.configure(new ClassloaderConfigurationProvider(LogConfigurationSample.class.getClassLoader(),
            new String[] { "com/microsoft/tfs/sdk/samples/console/log4j-warn.properties" //$NON-NLS-1$
            }), EnableReconfigurationPolicy.DISABLE_WHEN_EXTERNALLY_CONFIGURED,
            ResetConfigurationPolicy.RESET_EXISTING);

    logAllLevels(log, "WARN and above shown"); //$NON-NLS-1$
}

From source file:com.enrsx.wfs.snow.main.Main.java

/**
 * Main Entry point for the SNOW Lake Effect Snow App
 *
 * @param args cmdline arguments//  w  w w  . j  a va2s .c  o m
 */
public static void main(String[] args) {

    String propertiesPath = "./resources/admin.properties";
    String logDir = "./log";
    int logMaxSize = 250000;

    LogSetup.ConfigureLog(propertiesPath, logDir, logMaxSize);

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

    Calculate calculate = new Calculate();
    double outVar = calculate.getExtent();

    System.out.println(outVar);
}

From source file:com.rodaxsoft.mailgun.example.Main.java

public static void main(String[] args) {
    Log log = LogFactory.getLog(Main.class);

    final Client client = ClientBuilder.newClient();

    HttpAuthenticationFeature authFeature;
    authFeature = HttpAuthenticationFeature.basicBuilder().nonPreemptive()
            .credentials("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0").build();
    client.register(authFeature);/* w w w  .ja v  a2 s  .c  o m*/

    WebTarget webTarget = client.target("https://api.mailgun.net/v2/samples.mailgun.org").path("messages");

    Form form = new Form();
    form.param("to", "john@example.com");
    form.param("from", "noreply@example.com");
    form.param("subject", "Hello World");
    form.param("text", "This is my first Mailgun email from Java");
    //Set the Reply-TO header
    form.param("h:Reply-To", "support@example.com");

    Invocation.Builder invocationBuilder;
    invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON_TYPE);
    Response response = invocationBuilder.post(Entity.form(form));
    int status = response.getStatus();
    log.info("status = " + status);

    if (response.hasEntity()) {
        String json = response.readEntity(String.class);
        log.info("entity = " + json);
    }
}

From source file:com.github.cmisbox.core.Main.java

public static void main(String[] args) {
    Messages.init();//from  ww  w  . j  a  v  a  2 s . c o  m
    Config.getInstance();
    LogFactory.getLog(Main.class).info(Messages.startingCmisBox + "...");
    UI.getInstance();
    Watcher.getInstance();
    Storage.getInstance();
    CMISRepository.getInstance();

}

From source file:com.twitlinks.Main.java

/**
 * @param args//w w w.  ja v a2  s .c o  m
 * @throws ParseException 
 * @throws org.apache.lucene.queryParser.ParseException 
 * @throws IOException 
 * @throws InterruptedException 
 */
public static void main(String[] args)
        throws ParseException, IOException, org.apache.lucene.queryParser.ParseException, InterruptedException {
    Log log = LogFactory.getLog(Main.class);

    Parser parser = new Parser(true, "dataset_2m");
    parser.start();

    Indexer indexer = new Indexer();
    indexer.start();
    while (true) {
        try {
            Thread.sleep(2000);
            log.info(parser.getLinesRead() + ":" + indexer.docCount + ":" + Buffer.documentQueue.size());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        if (!parser.isAlive() && Buffer.documentQueue.size() == 0) {
            log.info(parser.getLinesRead() + ":" + indexer.docCount + ":" + Buffer.documentQueue.size());
            indexer.stopIndexing();
            break;
        }
    }

    //Test the simple search, current text:fantastic
    SimpleSearcher searcher = new SimpleSearcher();
    searcher.searcher();
}