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);
}
}
}
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");
}
}
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;
}
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!");
}
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");
}
}
Aggregations