Search in sources :

Example 6 with Log

use of org.apache.commons.logging.Log in project hadoop by apache.

the class AdHocLogDumper method dumpLogs.

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");
        }
        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);
            // 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);
        }
    }
}
Also used : Log(org.apache.commons.logging.Log) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) IOException(java.io.IOException) Log4JLogger(org.apache.commons.logging.impl.Log4JLogger) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) File(java.io.File)

Example 7 with Log

use of org.apache.commons.logging.Log in project ACS by ACS-Community.

the class PrintUtil method printPDF.

//
//  -- PRIVATE METHODS ---------------------------------------------
//
private void printPDF(String name, Printable printable) {
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(OrientationRequested.PORTRAIT);
    PrintService service = findPrinterService(flavor, aset);
    Assertion.assertTrue(service != null, "service != null");
    PrinterJob pj = PrinterJob.getPrinterJob();
    try {
        pj.setPrintService(service);
        pj.setPrintable(printable);
        pj.pageDialog(aset);
        pj.print(aset);
    } catch (PrinterException e) {
        Log log = LogFactory.getLog(PrintUtil.class);
        log.warn("The component " + name + " could not be printed");
    }
}
Also used : Log(org.apache.commons.logging.Log) PrinterException(java.awt.print.PrinterException) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintService(javax.print.PrintService) PrinterJob(java.awt.print.PrinterJob)

Example 8 with Log

use of org.apache.commons.logging.Log in project ACS by ACS-Community.

the class CommonsLoggingFactory method newInstance.

@Override
protected synchronized Log newInstance(String name) throws LogConfigurationException {
    //		System.out.println("CommonsLoggingFactoryForACS#newInstance called for name=" + name);
    // Check which framework is requesting the apache commons logger
    String loggerNameBase = null;
    StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
    for (StackTraceElement stackTraceElement : stackTrace) {
        if (stackTraceElement.getClassName().contains("org.apache.commons.scxml")) {
            loggerNameBase = SCXML_LOGGER_NAME_PREFIX;
            break;
        }
    // TODO: add check for other frameworks that use apache logging commons, once we have those
    }
    // Give up if we did not recognize the client framework
    if (loggerNameBase == null) {
        return super.newInstance(name);
    }
    // Check if we already have a logger for the client framework, and create it if needed.
    Log myLog = loggerMap.get(loggerNameBase);
    if (myLog == null) {
        final String loggerNameBaseFinal = loggerNameBase;
        myLog = new Jdk14Logger(loggerNameBase) {

            @Override
            public Logger getLogger() {
                // to some known framework loggers, in the absence of other specific log configuration.
                return ClientLogManager.getAcsLogManager().getLoggerForCorba(loggerNameBaseFinal, true);
            }
        };
        loggerMap.put(loggerNameBase, myLog);
    }
    return myLog;
}
Also used : Jdk14Logger(org.apache.commons.logging.impl.Jdk14Logger) Log(org.apache.commons.logging.Log) Logger(java.util.logging.Logger) Jdk14Logger(org.apache.commons.logging.impl.Jdk14Logger) LogConfigurationException(org.apache.commons.logging.LogConfigurationException)

Example 9 with Log

use of org.apache.commons.logging.Log in project android by JetBrains.

the class LibUnitTest method commonsLogging.

@Test
public void commonsLogging() {
    Log log = LogFactory.getLog(getClass());
    log.info("I can use commons-logging!");
}
Also used : Log(org.apache.commons.logging.Log) Test(org.junit.Test)

Example 10 with Log

use of org.apache.commons.logging.Log in project gocd by gocd.

the class BootstrapperLoggingHelper method setupDefaultLog4j.

private static void setupDefaultLog4j() {
    String logFile = System.getenv("LOG_FILE");
    System.out.println("logFile Environment Variable= " + logFile);
    try {
        if (logFile == null) {
            logFile = "go-agent-bootstrapper.log";
        }
        System.out.println("Logging to " + logFile);
        BasicConfigurator.configure(new FileAppender(LOG4J_PATTERN, logFile));
        Logger.getRootLogger().setLevel(Level.INFO);
    } catch (IOException e) {
        BasicConfigurator.configure(new ConsoleAppender(LOG4J_PATTERN));
        Logger.getRootLogger().setLevel(Level.INFO);
        Log LOG = LogFactory.getLog(BootstrapperLoggingHelper.class);
        LOG.warn("Unable to initialize log4j file-appender: " + logFile, e);
        LOG.warn("Using console-appender instead");
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) Log(org.apache.commons.logging.Log) IOException(java.io.IOException)

Aggregations

Log (org.apache.commons.logging.Log)188 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)40 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)35 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 BeanFactory (org.springframework.beans.factory.BeanFactory)17 CountDownLatch (java.util.concurrent.CountDownLatch)15 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)15 ArrayList (java.util.ArrayList)12 File (java.io.File)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11 MethodInvocation (org.aopalliance.intercept.MethodInvocation)10 IOException (java.io.IOException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)9 Message (org.springframework.messaging.Message)8 List (java.util.List)7 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)7 InputStream (java.io.InputStream)6 LogFactory (org.apache.commons.logging.LogFactory)6