Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Log Enhancement - resourceName is not appearing in the logs #3098

Open
chethan1999 opened this issue Sep 5, 2024 · 0 comments
Open

API Log Enhancement - resourceName is not appearing in the logs #3098

chethan1999 opened this issue Sep 5, 2024 · 0 comments

Comments

@chethan1999
Copy link

Description

Hi Team,

We want to enhance the API log and follow the document on wso2 website [1] , but the log doesn't show api resource (show only context and version) as mentioned on wso2 website.

Please kindly check the configuration we follow your document.

log4j2.properties


# Appender config API logging
appender.API_LOGFILE.type = RollingFile
appender.API_LOGFILE.name = API_LOGFILE
appender.API_LOGFILE.fileName = /repository/logs/api.log
appender.API_LOGFILE.filePattern = /repository/logs/api-%d{MM-dd-yyyy}-%i.log
appender.API_LOGFILE.layout.type = PatternLayout
#appender.API_LOGFILE.layout.pattern = [%d] %5p {%c} %X{apiName} - %m%ex%n
appender.API_LOGFILE.layout.pattern = [%d] %5p %c | %X{apiContext} | %X{tenantDomain} | %m%ex%n
appender.API_LOGFILE.policies.type = Policies
appender.API_LOGFILE.policies.time.type = TimeBasedTriggeringPolicy
appender.API_LOGFILE.policies.time.interval = 1
appender.API_LOGFILE.policies.time.modulate = true
appender.API_LOGFILE.policies.size.type = SizeBasedTriggeringPolicy
appender.API_LOGFILE.policies.size.size = 10MB
appender.API_LOGFILE.strategy.type = DefaultRolloverStrategy
appender.API_LOGFILE.strategy.max = 20
appender.API_LOGFILE.filter.threshold.type = ThresholdFilter
appender.API_LOGFILE.filter.threshold.level = DEBUG

API Log

[2024-08-26 11:08:14,970]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"sourceIP":"xx.xx.xx.xx","verb":"GET","correlationId":"8f56518f-aa4c-488d-8914-ac005f9d396a","apiTo":"/simple-test/1.0.0","flow":"REQUEST_IN"}
[2024-08-26 11:08:14,974]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"sourceIP":"xx.xx.xx.xx","verb":"GET","correlationId":"8f56518f-aa4c-488d-8914-ac005f9d396a","apiTo":"/simple-test/1.0.0","flow":"REQUEST_OUT"}
[2024-08-26 11:08:14,981]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"verb":"GET","correlationId":"8f56518f-aa4c-488d-8914-ac005f9d396a","apiTo":"/simple-test/1.0.0","flow":"RESPONSE_IN","statusCode":200}
[2024-08-26 11:08:14,981]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"verb":"GET","correlationId":"8f56518f-aa4c-488d-8914-ac005f9d396a","apiTo":"/simple-test/1.0.0","flow":"RESPONSE_OUT","statusCode":200}
[2024-08-26 11:08:16,373]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"sourceIP":"xx.xx.xx.xx","verb":"GET","correlationId":"fad9690c-af62-4df0-9d2c-a192b4bf79ed","apiTo":"/simple-test/1.0.0","flow":"REQUEST_IN"}
[2024-08-26 11:08:16,374]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"sourceIP":"xx.xx.xx.xx","verb":"GET","correlationId":"fad9690c-af62-4df0-9d2c-a192b4bf79ed","apiTo":"/simple-test/1.0.0","flow":"REQUEST_OUT"}
[2024-08-26 11:08:16,376]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"verb":"GET","correlationId":"fad9690c-af62-4df0-9d2c-a192b4bf79ed","apiTo":"/simple-test/1.0.0","flow":"RESPONSE_IN","statusCode":200}
[2024-08-26 11:08:16,377]  INFO API_LOG | /simple-test/1.0.0 | carbon.super | {"verb":"GET","correlationId":"fad9690c-af62-4df0-9d2c-a192b4bf79ed","apiTo":"/simple-test/1.0.0","flow":"RESPONSE_OUT","statusCode":200}

https://apim.docs.wso2.com/en/4.1.0/observe/api-manager/monitoring-api-logs/#configure-api-logs-using-devops-rest-api

Regards,
Chethan

Steps to Reproduce

We have received the above query from the customer regarding the API level logs and recreated the issue by following the below steps:

[2022-02-07 14:10:57,687]  INFO {API_LOG} pizzashack - {"sourceIP":"127.0.0.1","verb":"GET","correlationId":"684794db-c208-4777-ab93-c2b2422981fe","apiTo":"pizzashack/1.0.0/menu","flow":"REQUEST_IN"}
[2022-02-07 14:10:57,777]  INFO {API_LOG} pizzashack - {"sourceIP":"127.0.0.1","verb":"GET","correlationId":"684794db-c208-4777-ab93-c2b2422981fe","apiTo":"pizzashack/1.0.0/menu","flow":"REQUEST_OUT"}
[2022-02-07 14:10:58,601]  INFO {API_LOG} pizzashack - {"verb":"GET","correlationId":"684794db-c208-4777-ab93-c2b2422981fe","apiTo":"pizzashack/1.0.0/menu","flow":"RESPONSE_IN","statusCode":200}
[2022-02-07 14:10:58,603]  INFO {API_LOG} pizzashack - {"verb":"GET","correlationId":"684794db-c208-4777-ab93-c2b2422981fe","apiTo":"pizzashack/1.0.0/menu","flow":"RESPONSE_OUT","statusCode":200}
  • However, I couldn’t see the resourceName getting printed in the logs.

[2024-08-29 14:30:07,198] INFO {API_LOG} PizzaShackAPI | / | 1.0.0 | /pizzashack/1.0.0 | carbon.super - {"sourceIP":"127.0.0.1","verb":"OPTIONS","correlationId":"eff9659c-8ab7-4bdf-900e-daff1303dff1","apiTo":"/pizzashack/1.0.0","flow":"REQUEST_IN"}

  • Additionally, tried by adding additional properties in the log4j.properties as shown below:

appender.API_LOGFILE.layout.pattern = [%d] %5p {%c} %X{apiName} | %X{resourceName} | %X{apiVersion} | %X{apiContext} | %X{tenantDomain} - %m%ex%n

  • Still I couldn’t see anything related to the resourceName of the API.
[2024-08-29 14:43:43,829]  INFO {API_LOG} PizzaShackAPI | / | 1.0.0 | /pizzashack/1.0.0 | carbon.super - {"sourceIP":"127.0.0.1","verb":"POST","correlationId":"a392f441-e4b1-42de-9ff4-c99c53485aee","apiTo":"/pizzashack/1.0.0","flow":"REQUEST_IN"}
[2024-08-29 14:43:43,874]  INFO {API_LOG} PizzaShackAPI | / | 1.0.0 | /pizzashack/1.0.0 | carbon.super - {"verb":"POST","correlationId":"a392f441-e4b1-42de-9ff4-c99c53485aee","apiTo":"/pizzashack/1.0.0","flow":"RESPONSE_OUT","statusCode":401}

Affected Component

APIM

Version

4.1.0

Environment Details (with versions)

No response

Relevant Log Output

No response

Related Issues

No response

Suggested Labels

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant