【问题标题】:WSO2 API Manager, where can I find the log of gateway?WSO2 API Manager,在哪里可以找到网关的日志?
【发布时间】:2016-11-19 00:38:59
【问题描述】:

如标题,我在哪里可以找到仅关于api的请求和响应的网关日志?

wso2-apigw-trace.log的文件中,我什么也找不到。

【问题讨论】:

  • 它是否存储在数据库中?但我也找不到。

标签: wso2 wso2-am


【解决方案1】:

您可以使用这样的附加程序将突触线日志写入单独的文件。

# WIRE_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout.
log4j.appender.WIRE_LOGFILE=org.wso2.carbon.utils.logging.appenders.CarbonDailyRollingFileAppender
log4j.appender.WIRE_LOGFILE.File=${carbon.home}/repository/logs/${instance.log}/wso2wire${instance.log}.log
log4j.appender.WIRE_LOGFILE.Append=true
log4j.appender.WIRE_LOGFILE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout
log4j.appender.WIRE_LOGFILE.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n
log4j.appender.WIRE_LOGFILE.layout.TenantPattern=%U%@%D [%T] [%S]
log4j.appender.WIRE_LOGFILE.threshold=DEBUG
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG, WIRE_LOGFILE
log4j.additivity.org.apache.synapse.transport.http.wire=false

【讨论】:

  • 谢谢,Bhathiya。当我调用大量 API 时,如何确认日志属于哪个 API。以及如何获取org.wso2.carbon.apimgt.gateway.handlers.logging 的日志
  • 由于线路日志为请求和响应打印多行,因此您真的无法按 API 将所有内容组合在一起。
  • 开启handler调试日志,可以设置log4j.logger.org.wso2.carbon.apimgt.gateway.handlers=DEBUG
【解决方案2】:

如果你想用相关 id 记录请求和响应,你可以写一个custom sequence。相关 id 可以取自 message_id,如 this

【讨论】:

  • thx,Bhathiya。配置id后,我可以在哪个日志文件中找到消息?
  • <sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--Ext--In"> <property name="Authentication" expression="get-property('transport', 'Authentication')"/> <property name="Authorization" expression="get-property('Authentication')" scope="transport" type="STRING"/> <property name="Authentication" scope="transport" action="remove" /> </sequence>我在<APIM_HOME>/repository/deployment/server/synapse-configs/default/WSO2AM--Ext--In.xml上添加了这个
  • 如果你需要记录任何你需要使用日志中介的东西。 docs.wso2.com/display/ESB500/Log+Mediator
【解决方案3】:

您还可以通过管理门户中的日志分析器 UI 访问日志。

Here are the instructionsWSO2 API Cloud(API 管理器的托管版本)中了解如何执行此操作。

如果您想在日志中包含对后端的调用和响应的详细信息,您还需要添加将输出数据的中介策略。这可以在 API 编辑的第二步(“实施”)中完成,如下图所示:

API Cloud 已预先安装这些序列。对于您自己的 API Manager 部署,您必须手动上传它们。以下是 XML 文件:

流动中:

<sequence name="debug_in_flow" xmlns="http://ws.apache.org/ns/synapse">

 <log level="full" />
 <log level="custom">
    <property name="Host" expression="get-property('transport', 'Host')"/>
    <property name="Context" expression="get-property('To')"/>
    <property name="HTTP_METHOD" expression="get-property('axis2', 'HTTP_METHOD')"/>
    <property name="Resource" expression="$axis2:REST_URL_POSTFIX"/>
    <property name="Origin" expression="get-property('transport', 'Origin')"/>
    <property name="Content-Type" expression="get-property('transport', 'Content-Type')"/>
 </log>
</sequence>

输出流:

<sequence name="debug_out_flow" xmlns="http://ws.apache.org/ns/synapse">

    <log level="full" />
    <log level="custom">
        <property name="EndPoint" expression="get-property('ENDPOINT_PREFIX')"/>
        <property name="Content-Type" expression="get-property('transport', 'Content-Type')"/>
    </log>

</sequence>

故障流:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="debug_json_fault">

      <log level="custom">

         <property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
                   xmlns:ns3="http://org.apache.synapse/xsd"
                   name="ERROR_CODE"
                   expression="get-property('ERROR_CODE')"/>
         <property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
                   xmlns:ns3="http://org.apache.synapse/xsd"
                   name="ERROR_MESSAGE"
                   expression="get-property('ERROR_MESSAGE')"/>
         <property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
                   xmlns:ns3="http://org.apache.synapse/xsd"
                   name="ERROR_DETAIL"
                   expression="get-property('ERROR_DETAIL')"/>
         <property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
                   xmlns:ns3="http://org.apache.synapse/xsd"
               name="ERROR_EXCEPTION"
               expression="get-property('ERROR_EXCEPTION')"/>
     <property name="EndPoint" expression="get-property('ENDPOINT_PREFIX')"/>
     <property name="Content-Type" expression="get-property('transport', 'Content-Type')"/>
  </log>

<payloadFactory>
    <format>
        <am:fault xmlns:am="http://wso2.org/apimanager">
            <am:code>$1</am:code>
            <am:type>Status report</am:type>
            <am:message>Runtime Error</am:message>
            <am:description>$2</am:description>
        </am:fault>
    </format>
    <args>
        <arg expression="$ctx:ERROR_CODE"/>
        <arg expression="$ctx:ERROR_MESSAGE"/>
    </args>
</payloadFactory>
<filter xpath="$ctx:CUSTOM_HTTP_SC">
    <then>
        <property name="HTTP_SC" expression="$ctx:CUSTOM_HTTP_SC" scope="axis2"/>
    </then>
    <else>
        <property name="HTTP_SC" value="500" scope="axis2"/>
    </else>
</filter>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtFaultHandler"/>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="ContentType" scope="axis2" action="remove"/>
<property name="Authorization" scope="transport" action="remove"/>
<property name="Host" scope="transport" action="remove"/>
<property name="Accept" scope="transport" action="remove"/>
<property name="X-JWT-Assertion" scope="transport" action="remove"/>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
<drop/>

【讨论】:

    【解决方案4】:

    我想你可以从http_access_&lt;Date&gt;.log找到那些日志记录 文件路径&lt;APIM Home&gt;/repositary/logs/http_access_&lt;Date&gt;.log

    【讨论】:

    • 谢谢,JeewanaSL。在http_access_&lt;date&gt;.log的文件中,log太多,没有respones数据
    猜你喜欢
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    • 2018-10-31
    • 2019-11-11
    • 2023-03-15
    • 1970-01-01
    • 2019-06-03
    • 2022-01-23
    相关资源
    最近更新 更多