当前位置: 首页 > news >正文

玉树藏族自治州网站建设_网站建设公司_留言板_seo优化

有没有给做淘宝网站的,小程序的网址,网站备案有什么要求吗,中国网站建设集团很久以前#xff0c;我了解了一个称为Log MDC的东西#xff0c;我对此非常感兴趣。 我突然能够理解日志文件中发生的所有事情#xff0c;并指出特定的日志条目#xff0c;并找出对错#xff0c;特别是在调试生产中的错误时。 在2013年#xff0c;我受委托从事一个项目我了解了一个称为Log MDC的东西我对此非常感兴趣。 我突然能够理解日志文件中发生的所有事情并指出特定的日志条目并找出对错特别是在调试生产中的错误时。 在2013年我受委托从事一个项目该项目正在一些麻烦的水域几件事情的结合中运行几乎每个星期我不得不经历几次Java Thread Dump以弄清应用程序中发生的事情以使其停止。 另外有时我不得不将诸如AppDynamicjProfilerjConsole之类的探查器全部连接到应用程序以试图找出问题所在更重要的是是什么引发了问题。 jStack是我使用过的最有用的工具之一但是碰到的线程转储没有我可以使用的上下文信息。 我被困在看到10s个转储的堆栈跟踪中哪些类导致了该块但是没有有关什么是什么以及什么输入导致了该问题的信息并且它很快就令人沮丧。 最终我们找到了问题但是它们主要是在经过数轮深度调试后使用各种数据集对代码进行的。 一旦完成该项目我发誓我再也不会陷入那种境地了。 我探索了可以使用类似于Log4j的NDC但在线程中使用它的方式以便我的转储有意义。 而且我发现我可以更改ThreadName。 我的下一个项目确实非常有效地使用了它。 我最近遇到了一篇文章很好地解释了这个概念。 我不会重写他们所说的所有内容因此这里是他们博客文章的链接 。 所以上周我开始一个新项目当我开始编码框架时使用Spring 4.1和Spring Boot这是我为应用程序编写的第一个类并确保过滤器尽快进入代码。帮助我们进行后期制作但也使我的开发日志有意义。 下面是Log4j NDC和设置ThreadName的代码副本。 import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date;import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.filter.OncePerRequestFilter;/*** This is a very Spring opinionated HTTPFilter used for intercepting all requests and decorate the thread name with additional contextual* information. We have extenced the filter from {link OncePerRequestFilter} class provided by Spring Framework to ensure that the filter is absolutely * executd only once per request. * * The following information will be added:* ul* liOld Thread name: to ensure that we are not losing any original context with thread names;/li* liTime when the request was intercepted;/li* liThe RequestURI that proviced information on what RestFUL endpoint was accessed as part of this request;/li* liA Token that was received in the header. This token is encrypted and does not exposes any confidential information. Also, this token provides* context which helps during debugging;/li* liThe Payload from the token. This information will be very helpful when we have to debug for issues that may be happening with a call request* as this holds all the information sent from the called./li* /ul* * This filter will also reset the ThreadName back to its original name once the processing is complete.* * author Kapil Viren Ahuja**/ public class DecorateThreadNameFilter extends OncePerRequestFilter {Overrideprotected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)throws ServletException, IOException {final Logger LOGGER LoggerFactory.getLogger(DecorateThreadNameFilter.class);final SimpleDateFormat dateFormat new SimpleDateFormat(yyyy-MM-dd HH:mm:ss.SSS);Thread thread Thread.currentThread();String threadOriginalName thread.getName();String uri request.getRequestURI();String time dateFormat.format(new Date());String token request.getHeader(authorization);try {thread.setName(String.format(%s StartTime \%s\ RequestURI \%s\ Token \%s\, threadOriginalName, time, uri, token));} catch (Exception ex) {LOGGER.error(Failed to set the thread name., ex);// this is an internal filter and an error here should not impact// the request processing, hence eat the exception}try {filterChain.doFilter(request, response);} finally {try {thread.setName(threadOriginalName);} catch (Exception ex) {LOGGER.error(Failed to reset the thread name., ex);// this is an internal filter and an error here should not// impact the request processing, hence eat the exception}}} }/*** Generic filter for intercepting all requests and perform the following generic tasks:* * ul* liIntercepts the request and then pushed the user domain into the session if one exists./li* li Pushes a uniquely generated request identifier to the LOG4J NDC context. This identifier will then be prepended* to all log messages generated using LOG4J. This allows tracing all log messages generated as part of the same* request; /li* li Pushes the HTTP session identifier to the LOG4J NDC context. This identifier will then be prepended to all log* messages generated using LOG4J. This allows tracing all log messages generated as part of the same HTTP session;* /li* li Pushes the IP address of the client to the LOG4J NDC context. The IP address will then be prepended to all log* messages generated using LOG4J. This allows tying back multiple user sessions initiated with the same logon name to* be correctly tied back to their actual origins. /li* /ul*/ public class RequestInterceptorFilter implements Filter {/*** p* ul* liInitializes the LOG4J NDC context before executing an HTTP requests./li* liPushes the domain into the session/li* /ul* /p*/public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{HttpServletRequest httpRequest (HttpServletRequest) request;if (httpRequest.isRequestedSessionIdFromCookie() !httpRequest.isRequestedSessionIdValid()){// TODO: Need to define an session expiration page and redirect the application to that page// As of now this is a non-issue as we are handling session expirations on Flex (Front-end) and hence// no request will come to server in case the session timeout occurs// HttpServletResponse httpServletResponse (HttpServletResponse) response;// httpServletResponse.sendRedirect(httpRequest.getContextPath() ?expired);}else{// Create an NDC context string that will be prepended to all log messages written to files.org.apache.log4j.NDC.push(getContextualInformation(httpRequest));// Process the chain of filterschain.doFilter(request, response);// Clear the NDC context string so that if the thread is reused for another request, a new context string is// used.org.apache.log4j.NDC.remove();}}public void init(FilterConfig arg0) throws ServletException{}public void destroy(){}/*** p* Generates the Contextual information to be put in the log4js context. This information helps in tracing requests* /p* * param httpRequest* return*/private String getContextualInformation(HttpServletRequest httpRequest){String httpRequestIdentifier UUID.randomUUID().toString();String httpSessionIdentifier httpRequest.getSession().getId();String clientAddress httpRequest.getRemoteAddr();StringBuffer logNDC new StringBuffer(httpRequestIdentifier | httpSessionIdentifier | clientAddress);String userName (String)httpRequest.getSession().getAttribute(WebConstants.USERNAME);if (userName ! null){logNDC.append( | userName);}String domain (String)httpRequest.getSession().getAttribute(WebConstants.DOMAIN);if (domain ! null){logNDC.append( | domain);}// Create an NDC context string that will be prepended to all log messages written to files.return logNDC.toString();} }翻译自: https://www.javacodegeeks.com/2015/08/making-thread-dumps-intelligent.html
http://www.ihoyoo.com/news/98649.html

相关文章:

  • 网站搜索页面设计工程认证网站的建设
  • 强的网站建设公司开设计公司要怎么规划
  • 小城市企业网站建设闲鱼搭建网站
  • 五路居网站建设免费影视api接口app源码
  • 昆山网站建设方案优化公司南昌专门做网站
  • 站群论坛企业宣传网站建设
  • 长沙商城网站建设两学一做网站网站
  • 淄博做企业网站哪家好重庆公司注册地址
  • 长春网站建设方案策划郑州一核酸点推vip服务 年费320元
  • 世界各大网站搜索引擎提交入口往国外卖货的平台
  • 怎么做属于自己的领券网站拓者设计吧注册码是永久的吗
  • 安康市网站建设公司网站推广怎么做才有效果
  • 国外h5制作网站模板下载网站优化方案 site ww
  • 惠阳做网站公司网站的盈利点
  • 用php做电商网站网站长尾关键词排名软件
  • 成都电商网站网站关键词都在第二页
  • 网站seohtml网站开发目标
  • 建设网站硬件青岛电子商务网站建设
  • 怎么做网站互换链接wordpress主题背景图
  • 猜艺士科技网站建设怎么优化电脑系统
  • 网站做优化有什么用吗网站建设怎么把代码放入网站上
  • 梁露 网站建设与实践口腔网站建设
  • 广州网站优化关键词排名北京软件开发工程师
  • 上海营销网站建设公司网站建设建站网易互客
  • 芜湖哪家公司做网站不错wordpress数据库无法访问
  • 做电影网站用什么软件叫什么名字临沂网站建
  • 做徒步网站怎么样影院资讯 wordpress
  • 外贸建站与推广如何做机场网站建设需求
  • 河南城市建设招标类网站网站引用百度地图
  • 湛江市政工程建设公司网站如何做网站不被坑