List of usage examples for org.apache.commons.logging Log trace
void trace(Object message);
From source file:de.ufinke.cubaja.sort.SortManager.java
private void initTimer(final Log logger, final String prefix, final String key, final AtomicLong counter) { TimerTask task = new TimerTask() { public void run() { logger.trace(prefix + text.get(key, counter.get())); }//from w w w . ja v a 2 s. c o m }; timer = new Timer(); timer.schedule(task, logInterval, logInterval); }
From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java
/** * Logs the given message to the log at the trace level. If the log level is not enabled, this method does * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned. * * @param log the log where the messages will go * @param basename the base name of the resource bundle * @param locale the locale to determine what bundle to use * @param key the resource bundle key name * @param varargs arguments to help fill in the resource bundle message * * @return if the message was logged, a non-<code>null</code> Msg object is returned *//*www .j a va 2 s . co m*/ public static Msg trace(Log log, BundleBaseName basename, Locale locale, String key, Object... varargs) { if (log.isTraceEnabled()) { Msg msg = Msg.createMsg(basename, locale, key, varargs); log.trace((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg); return msg; } return null; }
From source file:com.lolay.google.geocode.GeocodeIntegration.java
public void testReverse() throws Exception { Log log = testReverseLog; GeocodeClient client = new ClientFactory(baseUrl).getGeocode(); GeocodeInvoker invoker = GeocodeInvoker.builder().latLng(40.714224D, -73.961452D).sensor(false).build(); GeocodeResponse response = null;/* w ww .ja v a 2s .c o m*/ try { long start = System.currentTimeMillis(); response = invoker.geocode(client); long end = System.currentTimeMillis(); log.trace(String.format("Reverse geocode took %s ms", end - start)); } catch (Exception e) { log.error(e); fail(); } assertNotNull(response); assertNotNull(response.getStatus()); assertEquals(GeocodeStatus.OK, response.getStatus()); assertNotNull(response.getResults()); assertEquals(8, response.getResults().size()); GeocodeResult result1 = response.getResults().get(0); assertNotNull(result1.getTypes()); assertEquals(Arrays.asList(GeocodeResultType.STREET_ADDRESS), result1.getTypes()); assertEquals("279-281 Bedford Ave, Brooklyn, NY 11211, USA", result1.getFormattedAddress()); assertNotNull(result1.getAddressComponents()); assertEquals(8, result1.getAddressComponents().size()); GeocodeAddressComponent addressComponent1 = result1.getAddressComponents().get(0); assertNotNull(addressComponent1.getTypes()); assertEquals(Arrays.asList(GeocodeAddressComponentType.STREET_NUMBER), addressComponent1.getTypes()); assertNotNull(addressComponent1.getLongName()); assertEquals("279-281", addressComponent1.getLongName()); assertNotNull(addressComponent1.getShortName()); assertEquals("279-281", addressComponent1.getShortName()); GeocodeGeometry geometry = result1.getGeometry(); assertNotNull(geometry); assertNotNull(geometry.getLocationType()); assertEquals(GeocodeLocationType.RANGE_INTERPOLATED, geometry.getLocationType()); validateLocation(geometry.getLocation(), 40.7142215D, -73.9614454D); validateFrame(geometry.getViewPort(), 40.7110552D, -73.9646313D, 40.7173505D, -73.9583361D); validateFrame(geometry.getBounds(), 40.7139010D, -73.9616800D, 40.7145047D, -73.9612874D); }
From source file:eu.qualityontime.commons.MethodUtils.java
/** * <p>//w ww . ja v a 2 s . c o m * Find an accessible method that matches the given name and has compatible * parameters. Compatible parameters mean that every method parameter is * assignable from the given parameters. In other words, it finds a method * with the given name that will take the parameters given. * </p> * * <p> * This method is slightly undeterministic since it loops through methods * names and return the first matching method. * </p> * * <p> * This method is used by * {@link #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}. * * <p> * This method can match primitive parameter by passing in wrapper classes. * For example, a <code>Boolean</code> will match a primitive * <code>boolean</code> parameter. * * @param clazz * find method in this class * @param methodName * find method with this name * @param parameterTypes * find method with compatible parameters * @return The accessible method */ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final String methodName, final Class<?>[] parameterTypes) { // trace logging final Log log = LogFactory.getLog(MethodUtils.class); if (log.isTraceEnabled()) { log.trace("Matching name=" + methodName + " on " + clazz); } final MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, false); // see if we can find the method directly // most of the time this works and it's much faster try { // Check the cache first Method method = getCachedMethod(md); if (method != null) { return method; } method = clazz.getMethod(methodName, parameterTypes); if (log.isTraceEnabled()) { log.trace("Found straight match: " + method); log.trace("isPublic:" + Modifier.isPublic(method.getModifiers())); } setMethodAccessible(method); // Default access superclass workaround cacheMethod(md, method); return method; } catch (final NoSuchMethodException e) { /* SWALLOW */ } // search through all methods final int paramSize = parameterTypes.length; Method bestMatch = null; final Method[] methods = clazz.getMethods(); float bestMatchCost = Float.MAX_VALUE; float myCost = Float.MAX_VALUE; for (final Method method2 : methods) { if (method2.getName().equals(methodName)) { // log some trace information if (log.isTraceEnabled()) { log.trace("Found matching name:"); log.trace(method2); } // compare parameters final Class<?>[] methodsParams = method2.getParameterTypes(); final int methodParamSize = methodsParams.length; if (methodParamSize == paramSize) { boolean match = true; for (int n = 0; n < methodParamSize; n++) { if (log.isTraceEnabled()) { log.trace("Param=" + parameterTypes[n].getName()); log.trace("Method=" + methodsParams[n].getName()); } if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) { if (log.isTraceEnabled()) { log.trace(methodsParams[n] + " is not assignable from " + parameterTypes[n]); } match = false; break; } } if (match) { // get accessible version of method final Method method = getAccessibleMethod(clazz, method2); if (method != null) { if (log.isTraceEnabled()) { log.trace(method + " accessible version of " + method2); } setMethodAccessible(method); // Default access // superclass // workaround myCost = getTotalTransformationCost(parameterTypes, method.getParameterTypes()); if (myCost < bestMatchCost) { bestMatch = method; bestMatchCost = myCost; } } log.trace("Couldn't find accessible method."); } } } } if (bestMatch != null) { cacheMethod(md, bestMatch); } else { // didn't find a match log.trace("No match found."); } return bestMatch; }
From source file:com.lolay.google.geocode.GeocodeIntegration.java
public void testForward() throws Exception { Log log = testForwardLog; GeocodeClient client = new ClientFactory(baseUrl).getGeocode(); GeocodeInvoker invoker = GeocodeInvoker.builder().address("1600 Amphitheatre Parkway, Mountain View, CA") .sensor(false).build();//from w w w . ja va 2s .c o m GeocodeResponse response = null; try { long start = System.currentTimeMillis(); response = invoker.geocode(client); long end = System.currentTimeMillis(); log.trace(String.format("Forward geocode took %s ms", end - start)); } catch (Exception e) { log.error(e); fail(); } assertNotNull(response); assertNotNull(response.getStatus()); assertEquals(GeocodeStatus.OK, response.getStatus()); assertNotNull(response.getResults()); assertEquals(1, response.getResults().size()); GeocodeResult result1 = response.getResults().get(0); assertNotNull(result1.getTypes()); assertEquals(Arrays.asList(GeocodeResultType.STREET_ADDRESS), result1.getTypes()); assertEquals("1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", result1.getFormattedAddress()); assertNotNull(result1.getAddressComponents()); assertEquals(8, result1.getAddressComponents().size()); GeocodeAddressComponent addressComponent1 = result1.getAddressComponents().get(0); assertNotNull(addressComponent1.getTypes()); assertEquals(Arrays.asList(GeocodeAddressComponentType.STREET_NUMBER), addressComponent1.getTypes()); assertNotNull(addressComponent1.getLongName()); assertEquals("1600", addressComponent1.getLongName()); assertNotNull(addressComponent1.getShortName()); assertEquals("1600", addressComponent1.getShortName()); GeocodeGeometry geometry = result1.getGeometry(); assertNotNull(geometry); assertNotNull(geometry.getLocationType()); assertEquals(GeocodeLocationType.ROOFTOP, geometry.getLocationType()); validateLocation(geometry.getLocation(), 37.4227820D, -122.0850990D); validateFrame(geometry.getViewPort(), 37.4196344D, -122.0882466D, 37.4259296D, -122.0819514D); assertNull(geometry.getBounds()); }
From source file:com.stevesouza.spring.contrib.JamonPerformanceMonitorInterceptor.java
/** * Wraps the invocation with a JAMon Monitor and writes the current * performance statistics to the log (if enabled). * @see com.jamonapi.MonitorFactory#start * @see com.jamonapi.Monitor#stop/*from w ww. ja v a 2s . c o m*/ */ @Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); MonKeyImp key = new MonKeyImp(name, name, "ms."); Monitor monitor = MonitorFactory.start(key); try { return invocation.proceed(); } catch (Throwable t) { if (this.trackExceptions) { trackException(key, t); } throw t; } finally { monitor.stop(); if (!this.trackAllInvocations || isLogEnabled(logger)) { logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor); } } }
From source file:com.googlecode.jcimd.PacketSerializer.java
private static Packet doDeserializePacket(InputStream inputStream, int maxMessageSize, boolean useChecksum, Log logger) throws IOException { ByteArrayOutputStream temp = new ByteArrayOutputStream(); int b;/*w w w.j av a 2 s . c o m*/ while ((b = inputStream.read()) != END_OF_STREAM) { // Any data transmitted between packets SHALL be ignored. if (b == STX) { temp.write(b); break; } } if (b != STX) { //throw new SoftEndOfStreamException(); throw new IOException("End of stream reached and still no <STX> byte"); } // Read the input stream until ETX while ((b = inputStream.read()) != END_OF_STREAM) { temp.write(b); if (b == ETX) { break; } if (temp.size() >= maxMessageSize) { // Protect from buffer overflow throw new IOException( "Buffer overflow reached at " + temp.size() + " byte(s) and still no <ETX> byte"); } } if (b != ETX) { throw new IOException("End of stream reached and still no <ETX> byte"); } // Parse contents of "temp" (it contains the entire CIMD message // including STX and ETX bytes). byte bytes[] = temp.toByteArray(); if (logger.isTraceEnabled()) { logger.trace("Received " + bytes.length + " byte(s)"); } if (useChecksum) { // Read two (2) bytes, just before the ETX byte. StringBuilder buffer = new StringBuilder(2); buffer.append((char) bytes[bytes.length - 3]); buffer.append((char) bytes[bytes.length - 2]); try { int checksum = Integer.valueOf(buffer.toString(), 16); int expectedChecksum = calculateCheckSum(bytes, 0, bytes.length - 3); if (checksum != expectedChecksum) { throw new IOException("Checksum error: expecting " + expectedChecksum + " but got " + checksum); } } catch (NumberFormatException e) { throw new IOException("Checksum error: expecting HEX digits, but got " + buffer); } } // Deserialize bytes, minus STX, CC (check sum), and ETX. int end = useChecksum ? bytes.length - 3 : bytes.length - 1; Packet packet = deserializeFromByteArray(bytes, 1, end); if (logger.isDebugEnabled()) { logger.debug("Received " + packet); } return packet; }
From source file:gov.nih.nci.cabig.caaers.tools.logging.CaaersLoggingAspect.java
private void log(Log logger, boolean entry, ProceedingJoinPoint call, Object retVal, long time, String userName) {/*from ww w . j a v a2 s . c o m*/ try { StringBuilder sb = new StringBuilder("[").append(userName).append("] - "); if (entry) { Object[] args = call.getArgs(); sb.append(entryMsgPrefix).append(" [").append(call.toShortString()).append(" ] with params { ") .append(String.valueOf(args != null && args.length > 0 ? args[0] : "")).append("}"); } else { sb.append(exitMsgPrefix).append(" [").append(call.toShortString()).append(" ] with return as: {") .append(String.valueOf(retVal)).append("} - executionTime : ").append(time); } logger.trace(sb.toString()); } catch (Exception e) { } }
From source file:net.fenyo.mail4hotspot.service.AdvancedServicesImpl.java
@Override public void testLog() { final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(getClass()); log.trace("testlog: TRACE"); log.fatal("testlog: FATAL"); log.error("testlog: ERROR"); log.info("testlog: INFO"); log.debug("testlog: DEBUG"); log.warn("testlog: WARN"); }
From source file:cn.scala.es.HeartBeat.java
HeartBeat(final Progressable progressable, Configuration cfg, TimeValue lead, final Log log) { Assert.notNull(progressable, "a valid progressable is required to report status to Hadoop"); TimeValue tv = HadoopCfgUtils.getTaskTimeout(cfg); Assert.isTrue(tv.getSeconds() <= 0 || tv.getSeconds() > lead.getSeconds(), "Hadoop timeout is shorter than the heartbeat"); this.progressable = progressable; long cfgMillis = (tv.getMillis() > 0 ? tv.getMillis() : 0); // the task is simple hence the delay = timeout - lead, that is when to start the notification right before the timeout this.delay = new TimeValue(Math.abs(cfgMillis - lead.getMillis()), TimeUnit.MILLISECONDS); this.log = log; String taskId;/*from w w w . ja va 2 s . c o m*/ TaskID taskID = HadoopCfgUtils.getTaskID(cfg); if (taskID == null) { log.warn("Cannot determine task id..."); taskId = "<unknown>"; if (log.isTraceEnabled()) { log.trace("Current configuration is " + HadoopCfgUtils.asProperties(cfg)); } } else { taskId = "" + taskID; } id = taskId; }