List of usage examples for org.apache.commons.logging Log warn
void warn(Object message);
From source file:org.apache.hadoop.hbase.util.ReflectionUtils.java
/** * Log the current thread stacks at INFO level. * @param log the logger that logs the stack trace * @param title a descriptive title for the call stacks * @param minInterval the minimum time from the last *///from w w w .j a va 2s.c o m public static void logThreadInfo(Log log, String title, long minInterval) { boolean dumpStack = false; if (log.isInfoEnabled()) { synchronized (ReflectionUtils.class) { long now = System.currentTimeMillis(); if (now - previousLogTime >= minInterval * 1000) { previousLogTime = now; dumpStack = true; } } if (dumpStack) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); printThreadInfo(new PrintStream(buffer, false, "UTF-8"), title); log.info(buffer.toString(Charset.defaultCharset().name())); } catch (UnsupportedEncodingException ignored) { log.warn("Could not write thread info about '" + title + "' due to a string encoding issue."); } } } }
From source file:org.apache.hadoop.hive.ql.exec.mr.Throttle.java
/** * Fetch http://tracker.om:/gc.jsp?threshold=period. *///from w ww. j a v a 2 s .c o m public static void checkJobTracker(JobConf conf, Log LOG) { try { byte[] buffer = new byte[1024]; int threshold = conf.getInt("mapred.throttle.threshold.percent", DEFAULT_MEMORY_GC_PERCENT); int retry = conf.getInt("mapred.throttle.retry.period", DEFAULT_RETRY_PERIOD); // If the threshold is 100 percent, then there is no throttling if (threshold == 100) { return; } // This is the Job Tracker URL String tracker = JobTrackerURLResolver.getURL(conf) + "/gc.jsp?threshold=" + threshold; while (true) { // read in the first 1K characters from the URL URL url = new URL(tracker); LOG.debug("Throttle: URL " + tracker); InputStream in = null; try { in = url.openStream(); in.read(buffer); in.close(); in = null; } finally { IOUtils.closeStream(in); } String fetchString = new String(buffer); // fetch the xml tag <dogc>xxx</dogc> Pattern dowait = Pattern.compile("<dogc>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); String[] results = dowait.split(fetchString); if (results.length != 2) { throw new IOException( "Throttle: Unable to parse response of URL " + url + ". Get retuned " + fetchString); } dowait = Pattern.compile("</dogc>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE); results = dowait.split(results[1]); if (results.length < 1) { throw new IOException( "Throttle: Unable to parse response of URL " + url + ". Get retuned " + fetchString); } // if the jobtracker signalled that the threshold is not exceeded, // then we return immediately. if (results[0].trim().compareToIgnoreCase("false") == 0) { return; } // The JobTracker has exceeded its threshold and is doing a GC. // The client has to wait and retry. LOG.warn("Job is being throttled because of resource crunch on the " + "JobTracker. Will retry in " + retry + " seconds.."); Thread.sleep(retry * 1000L); } } catch (Exception e) { LOG.warn("Job is not being throttled. " + e); } }
From source file:org.apache.hadoop.zebra.pig.TableStorer.java
@Override public void checkSchema(ResourceSchema schema) throws IOException { // Get schemaStr and sortColumnNames from the given schema. In the process, we // also validate the schema and sorting info. ResourceSchema.Order[] orders = schema.getSortKeyOrders(); boolean descending = false; for (ResourceSchema.Order order : orders) { if (order == ResourceSchema.Order.DESCENDING) { Log LOG = LogFactory.getLog(TableStorer.class); LOG.warn("Sorting in descending order is not supported by Zebra and the table will be unsorted."); descending = true;/*w ww.j a v a 2s . c o m*/ break; } } StringBuilder sortColumnNames = new StringBuilder(); if (!descending) { ResourceSchema.ResourceFieldSchema[] fields = schema.getFields(); int[] index = schema.getSortKeys(); for (int i = 0; i < index.length; i++) { ResourceFieldSchema field = fields[index[i]]; String name = field.getName(); if (name == null) throw new IOException("Zebra does not support column positional reference yet"); if (!org.apache.pig.data.DataType.isAtomic(field.getType())) throw new IOException( "Field [" + name + "] is not of simple type as required for a sort column now."); if (i > 0) sortColumnNames.append(","); sortColumnNames.append(name); } } // Convert resource schema to zebra schema org.apache.hadoop.zebra.schema.Schema zebraSchema; try { zebraSchema = SchemaConverter.convertFromResourceSchema(schema); } catch (ParseException ex) { throw new IOException("Exception thrown from SchemaConverter: " + ex.getMessage()); } Properties properties = UDFContext.getUDFContext().getUDFProperties(this.getClass(), new String[] { udfContextSignature }); properties.setProperty(UDFCONTEXT_OUTPUT_SCHEMA, zebraSchema.toString()); properties.setProperty(UDFCONTEXT_SORT_INFO, sortColumnNames.toString()); // This is to turn off type check for potential corner cases - for internal use only; if (System.getenv("zebra_output_checktype") != null && System.getenv("zebra_output_checktype").equals("no")) { properties.setProperty(UDFCONTEXT_OUTPUT_CHECKTYPE, "no"); } }
From source file:org.apache.jsieve.tests.AbstractTest.java
/** * Framework method validateArguments is invoked before a Sieve Test is * executed to validate its arguments. Subclass methods are expected to * override or extend this method to perform their own validation as * appropriate./*from w ww . j a va2 s . co m*/ * * @param arguments * @param context * <code>SieveContext</code> giving comntextual information, * not null * @throws SieveException */ protected void validateArguments(Arguments arguments, SieveContext context) throws SieveException { if (!arguments.getArgumentList().isEmpty()) { final Log logger = context.getLog(); if (logger.isWarnEnabled()) { logger.warn("Unexpected arguments for " + getClass().getName()); } context.getCoordinate().logDiagnosticsInfo(logger); logger.debug(arguments); final String message = context.getCoordinate().addStartLineAndColumn("Found unexpected arguments."); throw new SyntaxException(message); } }
From source file:org.apache.logging.log4j.jcl.CallerInformationTest.java
@Test public void testClassLogger() throws Exception { final ListAppender app = ctx.getListAppender("Class").clear(); final Log logger = LogFactory.getLog("ClassLogger"); logger.info("Ignored message contents."); logger.warn("Verifying the caller class is still correct."); logger.error("Hopefully nobody breaks me!"); final List<String> messages = app.getMessages(); assertEquals("Incorrect number of messages.", 3, messages.size()); for (final String message : messages) { assertEquals("Incorrect caller class name.", this.getClass().getName(), message); }/*from ww w . ja va2 s .c o m*/ }
From source file:org.apache.logging.log4j.jcl.CallerInformationTest.java
@Test public void testMethodLogger() throws Exception { final ListAppender app = ctx.getListAppender("Method").clear(); final Log logger = LogFactory.getLog("MethodLogger"); logger.info("More messages."); logger.warn("CATASTROPHE INCOMING!"); logger.error("ZOMBIES!!!"); logger.warn("brains~~~"); logger.info("Itchy. Tasty."); final List<String> messages = app.getMessages(); assertEquals("Incorrect number of messages.", 5, messages.size()); for (final String message : messages) { assertEquals("Incorrect caller method name.", "testMethodLogger", message); }//w ww . ja v a2s .c om }
From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java
public static boolean repairIdentifierAttribute(Element element, String attributeName, Identifier identifierDefault, Log logger) throws DOMStructureException { Identifier identifier = getIdentifierAttribute(element, attributeName); if (identifier == null) { if (identifierDefault != null) { identifier = identifierDefault; } else {/*from ww w. j a va2 s . co m*/ identifier = IdentifierImpl.gensym("urn:" + attributeName.toLowerCase()); } logger.warn("Setting missing " + attributeName + " attribute to " + identifier.stringValue()); element.setAttribute(attributeName, identifier.stringValue()); return true; } return false; }
From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java
public static boolean repairIdentifierContent(Element element, Log logger) throws DOMStructureException { Identifier identifier = getIdentifierContent(element); if (identifier == null) { identifier = IdentifierImpl.gensym(); logger.warn("Setting missing content to " + identifier.stringValue()); element.setTextContent(identifier.stringValue()); return true; }//from w w w. j ava 2 s . c o m return false; }
From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java
public static boolean repairBooleanAttribute(Element element, String attributeName, boolean bvalue, Log logger) throws DOMStructureException { Boolean booleanValue = null;/*from w ww .j ava 2 s . co m*/ try { booleanValue = getBooleanAttribute(element, attributeName); } catch (DOMStructureException ex) { logger.warn("Setting invalid " + attributeName + " attribute to " + bvalue); element.setAttribute(attributeName, Boolean.toString(bvalue)); return true; } if (booleanValue == null) { logger.warn("Setting missing " + attributeName + " attribute to " + bvalue); element.setAttribute(attributeName, Boolean.toString(bvalue)); return true; } return false; }
From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java
public static boolean repairVersionAttribute(Element element, String attributeName, Log logger) { String versionString = getStringAttribute(element, attributeName); if (versionString == null) { logger.warn("Adding default " + attributeName + " string 1.0"); element.setAttribute(attributeName, "1.0"); return true; }// w w w . j a va2 s . c om try { StdVersion.newInstance(versionString); } catch (ParseException ex) { logger.warn("Setting invalid " + attributeName + " string " + versionString + " to 1.0", ex); element.setAttribute(attributeName, "1.0"); return true; } return false; }