Java Code Examples for com.dianping.cat.Cat#logError()
The following examples show how to use
com.dianping.cat.Cat#logError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatAopService.java From piggymetrics with MIT License | 6 votes |
@Around("@annotation(CatAnnotation)") public Object aroundMethod(ProceedingJoinPoint pjp) { MethodSignature joinPointObject = (MethodSignature) pjp.getSignature(); Method method = joinPointObject.getMethod(); Transaction t = Cat.newTransaction("method", method.getName()); try { Object obj = pjp.proceed(); t.setSuccessStatus(); return obj; } catch (Throwable e) { t.setStatus(e); Cat.logError(e); throw new RuntimeException("Exception thrown by CAT aop", e); } finally { t.complete(); } }
Example 2
Source File: CatAopService.java From piggymetrics with MIT License | 6 votes |
@Around("@annotation(CatAnnotation)") public Object aroundMethod(ProceedingJoinPoint pjp) { MethodSignature joinPointObject = (MethodSignature) pjp.getSignature(); Method method = joinPointObject.getMethod(); Transaction t = Cat.newTransaction("method", method.getName()); try { Object obj = pjp.proceed(); t.setSuccessStatus(); return obj; } catch (Throwable e) { t.setStatus(e); Cat.logError(e); throw new RuntimeException("Exception thrown by CAT aop", e); } finally { t.complete(); } }
Example 3
Source File: CatFilter.java From Zebra with Apache License 2.0 | 6 votes |
@Override public int executeShardUpdate(ShardStatement source, String sql, int autoGeneratedKeys, int[] columnIndexes, String[] columnNames, JdbcFilter chain) throws SQLException { SqlAliasManager.setSqlAlias(sql); Transaction t = Cat.newTransaction(SHARD_CAT_TYPE, SqlAliasManager.getSqlAlias()); int result; try { result = chain.executeShardUpdate(source, sql, autoGeneratedKeys, columnIndexes, columnNames, chain); t.setStatus(Message.SUCCESS); } catch (Throwable exp) { Cat.logError(exp); t.setStatus(exp); throw new SQLException(exp); } finally { t.complete(); } return result; }
Example 4
Source File: CatFilter.java From Zebra with Apache License 2.0 | 6 votes |
@Override public SingleConnection getSingleConnection(SingleDataSource source, JdbcFilter chain) throws SQLException { Transaction t = null; try { t = Cat.newTransaction("SQL.Conn", source.getConfig().getId()); SingleConnection conn = chain.getSingleConnection(source, chain); t.setStatus(Transaction.SUCCESS); return conn; } catch (SQLException exp) { Transaction sqlTransaction = Cat.newTransaction("SQL", DaoContextHolder.getSqlName()); try { Cat.logEvent("SQL.Database", source.getConfig().getJdbcUrl(), "ERROR", source.getConfig().getId()); Cat.logError(exp); sqlTransaction.setStatus(exp); } finally { sqlTransaction.complete(); } throw exp; } finally { if (t != null) { t.complete(); } } }
Example 5
Source File: CatAppender4Log4j2.java From x-pipe with Apache License 2.0 | 6 votes |
private void logError(LogEvent event) { Throwable info = event.getThrown(); if (info != null) { Throwable exception = info; Object message = event.getMessage(); String extra = ExceptionUtils.extractExtraMessage(info); String logMessage = StringUtil.join(",", message, extra); if (!StringUtil.isEmpty(logMessage)) { Cat.logError(logMessage, exception); } else { Cat.logError(exception); } } }
Example 6
Source File: CatAopService.java From piggymetrics with MIT License | 6 votes |
@Around("@annotation(CatAnnotation)") public Object aroundMethod(ProceedingJoinPoint pjp) { MethodSignature joinPointObject = (MethodSignature) pjp.getSignature(); Method method = joinPointObject.getMethod(); Transaction t = Cat.newTransaction("method", method.getName()); try { Object obj = pjp.proceed(); t.setSuccessStatus(); return obj; } catch (Throwable e) { t.setStatus(e); Cat.logError(e); throw new RuntimeException("Exception thrown by CAT aop", e); } finally { t.complete(); } }
Example 7
Source File: ConfigSubscriber.java From AsuraFramework with Apache License 2.0 | 5 votes |
/** * 初始化zk连接 * * @author zhangshaobin * @created 2013-6-26 上午10:21:34 */ private void init() { applicationName = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.CONFIG_APPLICATION_NAME_KEY, null).get(); String zkConfigEnsemble = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.ZK_ENSEMABLE_KEY, null).get(); Integer zkConfigSessionTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_SESSION_TIMEOUT_KEY, 15000).get(); Integer zkConfigConnTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_CONN_TIMEOUT_KEY, 5000).get(); Transaction tran = Cat.newTransaction("Asura Configuration init", applicationName + "_" + zkConfigEnsemble); try { if (Check.NuNStr(zkConfigEnsemble)) { logger.warn("ZooKeeper configuration running in file mode, zk is not enabled since not configured"); Cat.logError("zk is not enabled since not configured", new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started.")); return; } client = createAndStartZKClient(zkConfigEnsemble, zkConfigSessionTimeout, zkConfigConnTimeout); if (client.getState() != CuratorFrameworkState.STARTED) { throw new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started."); } tran.setStatus(Transaction.SUCCESS); } catch (Exception e) { logger.error("连接配置中心服务器超时,时间5000毫秒。", e); Cat.logError("asura configuration init exception", e); tran.setStatus(e); System.exit(1); } finally { tran.complete(); } logger.info(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ").format(new Date()) + applicationName + " connected to cofnig server(" + zkConfigEnsemble + ")."); logger.info(applicationName + " connected to cofnig server(" + zkConfigEnsemble + ")."); }
Example 8
Source File: DefaultProducer.java From hermes with Apache License 2.0 | 5 votes |
@Override public Future<SendResult> send() { Transaction t = null; if (m_config.isCatEnabled()) { t = Cat.newTransaction(CatConstants.TYPE_MESSAGE_PRODUCE_TRIED, m_msg.getTopic()); } try { Topic topic = m_metaService.findTopicByName(m_msg.getTopic()); if (topic == null) { log.error("Topic {} not found.", m_msg.getTopic()); throw new IllegalArgumentException(String.format("Topic %s not found.", m_msg.getTopic())); } if (Storage.KAFKA.equals(topic.getStorageType())) { m_msg.setWithCatTrace(false); } m_msg.setBornTime(m_systemClockService.now()); Future<SendResult> future = m_pipeline.put(m_msg); if (t != null) { t.setStatus(Transaction.SUCCESS); } return future; } catch (Exception e) { if (t != null) { Cat.logError(e); t.setStatus(e); } throw e; } finally { if (t != null) { t.complete(); } } }
Example 9
Source File: CatServletFilter.java From piggymetrics with MIT License | 5 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String url = request.getRequestURL().toString(); for (String urlPattern : urlPatterns) { if (url.startsWith(urlPattern)) { url = urlPattern; } } CatContext catContext = new CatContext(); catContext.addProperty(Cat.Context.ROOT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID)); catContext.addProperty(Cat.Context.PARENT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID)); catContext.addProperty(Cat.Context.CHILD, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID)); Cat.logRemoteCallServer(catContext); Transaction t = Cat.newTransaction("Service", url); try { Cat.logEvent("Service.method", request.getMethod(), Message.SUCCESS, request.getRequestURL().toString()); Cat.logEvent("Service.client", request.getRemoteHost()); filterChain.doFilter(servletRequest, servletResponse); t.setStatus(Transaction.SUCCESS); } catch (Exception ex) { t.setStatus(ex); Cat.logError(ex); throw ex; } finally { t.complete(); } }
Example 10
Source File: CatServletFilter.java From piggymetrics with MIT License | 5 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String url = request.getRequestURL().toString(); for (String urlPattern : urlPatterns) { if (url.startsWith(urlPattern)) { url = urlPattern; } } CatContext catContext = new CatContext(); catContext.addProperty(Cat.Context.ROOT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID)); catContext.addProperty(Cat.Context.PARENT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID)); catContext.addProperty(Cat.Context.CHILD, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID)); Cat.logRemoteCallServer(catContext); Transaction t = Cat.newTransaction("Service", url); try { Cat.logEvent("Service.method", request.getMethod(), Message.SUCCESS, request.getRequestURL().toString()); Cat.logEvent("Service.client", request.getRemoteHost()); filterChain.doFilter(servletRequest, servletResponse); t.setStatus(Transaction.SUCCESS); } catch (Exception ex) { t.setStatus(ex); Cat.logError(ex); throw ex; } finally { t.complete(); } }
Example 11
Source File: RabbitMqSendClient.java From AsuraFramework with Apache License 2.0 | 5 votes |
private void sendQueue(QueueName queueName, RabbitMessage rm) throws Exception { if (rm == null || queueName == null) { return; } initQueueChannel(); String _queueName = queueName.getNameByEnvironment(environment); Transaction trans = Cat.newTransaction("RabbitMQ Message", "PUBLISH-QUEUE-" + _queueName); Cat.logEvent("mq send queue", _queueName, Event.SUCCESS,rm.toJsonStr()); try { queueChannel.queueDeclare(_queueName, true, false, false, null); queueChannel.basicPublish("", _queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, rm.toJsonStr().getBytes("UTF-8")); if (LOGGER.isInfoEnabled()) { LOGGER.info("SEND SUCCESS:[queue:{},message:{}]", _queueName, rm.toJsonStr()); } Cat.logMetricForCount("PUBLISH-QUEUE-" + _queueName); // 统计请求次数, 可以查看对应队列中放入了多少信息 trans.setStatus(Transaction.SUCCESS); } catch (Exception e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("SEND ERROR:[queue:{},message:{},exception:{}]", _queueName, rm.toJsonStr(), e); } String err = queueName + " rabbitmq发送消息异常"; Cat.logError(err, e); trans.setStatus(e); throw new AsuraRabbitMqException(err, e); } finally { trans.complete(); } }
Example 12
Source File: EchoClientStarter.java From x-pipe with Apache License 2.0 | 5 votes |
private static void doConnect(String host, int port, String protocol, int speed) { AdvancedEchoClient client = new AdvancedEchoClient(host, port, protocol, speed); Cat.logEvent("Start", System.nanoTime()+""); try { client.startServer().channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); logger.error("[doConnect]", e); Cat.logError("ReConnected", e); } finally { scheduled.schedule(()->doConnect(host, port, protocol, speed), 1, TimeUnit.MINUTES); } }
Example 13
Source File: CatServletFilter.java From cat_lab with MIT License | 5 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String url = request.getRequestURL().toString(); for (String urlPattern : urlPatterns) { if (url.startsWith(urlPattern)) { url = urlPattern; } } CatContext catContext = new CatContext(); catContext.addProperty(Cat.Context.ROOT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID)); catContext.addProperty(Cat.Context.PARENT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID)); catContext.addProperty(Cat.Context.CHILD, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID)); Cat.logRemoteCallServer(catContext); Transaction t = Cat.newTransaction(CatConstants.TYPE_SERVICE, url); try { Cat.logEvent("Service.method", request.getMethod(), Message.SUCCESS, request.getRequestURL().toString()); Cat.logEvent("Service.client", request.getRemoteHost()); filterChain.doFilter(servletRequest, servletResponse); t.setStatus(Transaction.SUCCESS); } catch (Exception ex) { t.setStatus(ex); Cat.logError(ex); throw ex; } finally { t.complete(); } }
Example 14
Source File: MobileExecuteRoute.java From s2g-zuul with MIT License | 5 votes |
@Override public void run() { try { final CloseableHttpClient hc = clientRef.get(); if (hc == null) return; hc.getConnectionManager().closeExpiredConnections(); } catch (Throwable t) { Cat.logError("error closing expired connections", t); } }
Example 15
Source File: CatServletFilter.java From s2g-zuul with MIT License | 5 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String url = request.getRequestURL().toString(); for (String urlPattern : urlPatterns) { if (url.startsWith(urlPattern)) { url = urlPattern; } } Transaction t = Cat.newTransaction("Service", url); try { PropertyContext propertyContext = new PropertyContext(); propertyContext.addProperty(Cat.Context.ROOT, request.getHeader(Constants.CAT_ROOT_MESSAGE_ID)); propertyContext.addProperty(Cat.Context.PARENT, request.getHeader(Constants.CAT_PARENT_MESSAGE_ID)); propertyContext.addProperty(Cat.Context.CHILD, request.getHeader(Constants.CAT_CHILD_MESSAGE_ID)); Cat.logRemoteCallServer(propertyContext); Cat.logEvent("Service.method", request.getMethod(), Message.SUCCESS, request.getRequestURL().toString()); Cat.logEvent("Service.client", request.getRemoteHost()); filterChain.doFilter(servletRequest, servletResponse); t.setStatus(Transaction.SUCCESS); } catch (Exception ex) { t.setStatus(ex); Cat.logError(ex); throw ex; } finally { t.complete(); } }
Example 16
Source File: SyncZuulServlet.java From s2g-zuul with MIT License | 5 votes |
/** * sets error context info and executes "error" filters * * @param e * @throws ZuulException */ void error(ZuulException e) { try { RequestContext.getCurrentContext().setThrowable(e); zuulRunner.error(); } catch (Throwable t) { Cat.logError(t); LOGGER.error(e.getMessage(), e); }finally{ Cat.logError(e); } }
Example 17
Source File: CatServletFilter.java From cat_lab with MIT License | 5 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String url = request.getRequestURL().toString(); for (String urlPattern : urlPatterns) { if (url.startsWith(urlPattern)) { url = urlPattern; } } CatContext catContext = new CatContext(); catContext.addProperty(Cat.Context.ROOT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID)); catContext.addProperty(Cat.Context.PARENT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID)); catContext.addProperty(Cat.Context.CHILD, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID)); Cat.logRemoteCallServer(catContext); Transaction t = Cat.newTransaction(CatConstants.TYPE_SERVICE, url); try { Cat.logEvent("Service.method", request.getMethod(), Message.SUCCESS, request.getRequestURL().toString()); Cat.logEvent("Service.client", request.getRemoteHost()); filterChain.doFilter(servletRequest, servletResponse); t.setStatus(Transaction.SUCCESS); } catch (Exception ex) { t.setStatus(ex); Cat.logError(ex); throw ex; } finally { t.complete(); } }
Example 18
Source File: CatServletFilter.java From cat_lab with MIT License | 5 votes |
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) servletRequest; String url = request.getRequestURL().toString(); for (String urlPattern : urlPatterns) { if (url.startsWith(urlPattern)) { url = urlPattern; } } CatContext catContext = new CatContext(); catContext.addProperty(Cat.Context.ROOT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID)); catContext.addProperty(Cat.Context.PARENT, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID)); catContext.addProperty(Cat.Context.CHILD, request.getHeader(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID)); Cat.logRemoteCallServer(catContext); Transaction t = Cat.newTransaction(CatConstants.TYPE_URL, url); try { Cat.logEvent("Service.method", request.getMethod(), Message.SUCCESS, request.getRequestURL().toString()); Cat.logEvent("Service.client", request.getRemoteHost()); filterChain.doFilter(servletRequest, servletResponse); t.setStatus(Transaction.SUCCESS); } catch (Exception ex) { t.setStatus(ex); Cat.logError(ex); throw ex; } finally { t.complete(); } }
Example 19
Source File: MobileExecuteRoute.java From s2g-zuul with MIT License | 4 votes |
@Override public Object run() throws ZuulException { Transaction tran = Cat.getProducer().newTransaction("Filter", "ExecuteRoute"); RequestContext ctx = RequestContext.getCurrentContext(); HttpServletRequest request = ctx.getRequest(); String url = ctx.getRouteUrl().toString(); String groupName = null; String routeName = null; try { Cat.logEvent("route.url", url); HttpClient httpclient = clientRef.get(); Collection<Header> headers = buildZuulRequestHeaders(request); InputStream requestEntity = getRequestBody(request); int contentLength = request.getContentLength(); groupName = ctx.getRouteGroup(); routeName = ctx.getRouteName(); if (groupName == null) groupName = Constants.DEFAULT_GROUP; if (routeName == null) routeName = Constants.DEFAULT_NAME; RequestConfig requestConfig = buildRequestConfig(routeName, groupName); String verb = request.getMethod().toUpperCase(); HttpResponse response = forward(httpclient, requestConfig, verb, url, headers, requestEntity, contentLength, groupName, routeName); setResponse(response); tran.setStatus(Transaction.SUCCESS); } catch (Exception e) { tran.setStatus(e); String originUrl = getOriginatingURL(); String targetUrl = url; String targetIp = "unknown"; try { targetIp = InetAddress.getByName(ctx.getRouteUrl().getHost()).getHostAddress(); } catch (Exception ignore) { } Exception ex = e; //String errorMsg =String.format("[${ex.class.simpleName}]{${ex.message}} "); String errorMsg =String.format("[%s]{%s} ",ex.getClass().getSimpleName(),ex.getMessage()); Throwable cause = null; while ((cause = ex.getCause()) != null) { ex = (Exception) cause; //errorMsg = "${errorMsg}[${ex.class.simpleName}]{${ex.message}} "; errorMsg += String.format("[%s]{%s} ",ex.getClass().getSimpleName(),ex.getMessage()); } //Cat.logError("Service Execution Error,OriginUrl: ${originUrl}\nTargetUrl: ${targetUrl}\nTargetIp: ${targetIp}\nCause: ${errorMsg}", e); Cat.logError(String.format("Service Execution Error,OriginUrl: %s\nTargetUrl: %s\nTargetIp: %s\nCause: %s\n,groupName:%s\n,routeName:%s",originUrl,targetUrl,targetIp,errorMsg,groupName,routeName), e); //throw new ZuulException(errorMsg,500, "TargetUrl: ${targetUrl}\nCause: ${errorMsg}"); throw new ZuulException(errorMsg,500, String.format("TargetUrl: %s\nCause: %s",targetUrl,errorMsg)); } finally { tran.complete(); } return null; }
Example 20
Source File: BaseMessageListener.java From hermes with Apache License 2.0 | 4 votes |
@Override public void onMessage(List<ConsumerMessage<T>> msgs) { if (msgs != null && !msgs.isEmpty()) { String topic = msgs.get(0).getTopic(); for (ConsumerMessage<T> msg : msgs) { Transaction t = Cat.newTransaction(CatConstants.TYPE_MESSAGE_CONSUMED, topic + ":" + m_groupId); MessageTree tree = Cat.getManager().getThreadLocalMessageTree(); if (msg instanceof PropertiesHolderAware) { PropertiesHolder holder = ((PropertiesHolderAware) msg).getPropertiesHolder(); String rootMsgId = holder.getDurableSysProperty(CatConstants.ROOT_MESSAGE_ID); String parentMsgId = holder.getDurableSysProperty(CatConstants.CURRENT_MESSAGE_ID); tree.setRootMessageId(rootMsgId); tree.setParentMessageId(parentMsgId); } try { t.addData("topic", topic); t.addData("key", msg.getRefKey()); t.addData("groupId", m_groupId); setOnMessageStartTime(msg); onMessage(msg); setOnMessageEndTime(msg); // by design, if nacked, no effect msg.ack(); String ip = NetworkInterfaceManager.INSTANCE.getLocalHostAddress(); Cat.logEvent("Consumer:" + ip, msg.getTopic() + ":" + m_groupId, Event.SUCCESS, "key=" + msg.getRefKey()); Cat.logEvent("Message:" + topic, "Consumed:" + ip, Event.SUCCESS, "key=" + msg.getRefKey()); Cat.logMetricForCount(msg.getTopic()); t.setStatus(MessageStatus.SUCCESS.equals(msg.getStatus()) ? Transaction.SUCCESS : "FAILED-WILL-RETRY"); } catch (Exception e) { Cat.logError(e); t.setStatus(e); log.error("Exception occurred while calling onMessage.", e); msg.nack(); } finally { t.complete(); } } } }