简体   繁体   English

WSO2IS将客户端IP记录到文件wso2carbon.log中

[英]WSO2IS logging client IP into file wso2carbon.log

我有一个WSO2IS位于平衡器后面的环境,希望客户端IP也可以登录到http_access.log文件之外的文件wso2carbon.log中。

on application log we need to manually parse the value to log. 在应用程序日志中,我们需要手动解析该值以进行记录。 you shall get the IP address from request. 您将从请求中获取IP地址。 You may add this to Thread local and configure it as pattern layout[5]. 您可以将其添加到“线程本地”并将其配置为模式布局[5]。

   String ipAddress = request.getHeader("X-FORWARDED-FOR");  
   if (ipAddress == null) {  
       ipAddress = request.getRemoteAddr();  
   }

You may use request header "X-Forwarded-For"[1]. 您可以使用请求标头“ X-Forwarded-For” [1]。

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="${carbon.home}/repository/logs"
               prefix="http_access_management_console_" suffix=".log"
               pattern="%{X-Forwarded-For}i %h %l %u %t &quot;%r&quot; %s %b &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;" />

[2] [2]

[1]. [1]。 https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Proxies_Support [2]. https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html#Proxies_Support [2]。 https://docs.wso2.com/display/ESB490/Access+Logs https://docs.wso2.com/display/ESB490/Access+Logs

[3]. [3]。 http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html#Access_Log_Valve http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html#Access_Log_Valve

[4]. [4]。 http://www.techstacks.com/howto/configure-access-logging-in-tomcat.html [5]. http://www.techstacks.com/howto/configure-access-logging-in-tomcat.html [5]。 https://logging.apache.org/log4j/2.x/manual/thread-context.html https://logging.apache.org/log4j/2.x/manual/thread-context.html

If you can programmatically get the User's IP, then you can write a User Operation Event Listener [1] and print logs. 如果可以通过编程方式获取用户的IP,则可以编写用户操作事件监听器[1]并打印日志。 A sample is in [2]. 样本在[2]中。

[1] http://tharindue.blogspot.com/2016/08/user-operation-event-listener-in-wso2.html [2] http://tharindue.blogspot.com/2016/08/writing-user-operation-event-listener.html [1] http://tharindue.blogspot.com/2016/08/user-operation-event-listener-in-wso2.html [2] http://tharindue.blogspot.com/2016/08/writing-user -operation-event-listener.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM