Home > front end >  Removing older http_access logs - WSO2 APIM 3.2.0 and WSO2 IS 5.11.0
Removing older http_access logs - WSO2 APIM 3.2.0 and WSO2 IS 5.11.0

Time:11-16

I am using WSO2 APIM 3.2.0 and WSO2 IS 5.11.0.

I have logs in directory ${sys:carbon.home}/repository/logs/

I could manage the log growth by removing the older files more than 30 days by adding the below configuration in ${sys:carbon.home}/repository/conf/log4j2.properties

appender.ERROR_LOGFILE.strategy.action.type = Delete
appender.ERROR_LOGFILE.strategy.action.basepath = 
${sys:carbon.home}/repository/logs/
appender.ERROR_LOGFILE.strategy.action.maxdepth = 1
appender.ERROR_LOGFILE.strategy.action.condition.type = IfLastModified
appender.ERROR_LOGFILE.strategy.action.condition.age = 30D
appender.ERROR_LOGFILE.strategy.action.PathConditions.type = IfFileName
appender.ERROR_LOGFILE.strategy.action.PathConditions.glob = wso2-apigw-errors-*

I can do the same for wso2carbon, audit logs but the log4j2.properties has no support for http_access logs.

In ${sys:carbon.home}/repository/conf/tomcat/catalina-server.xml, AccessLogValve has control for http_access logs.

I am not sure how to remove the older logs using this XML file. Can someone let me know how it can be done?

CodePudding user response:

As you have correctly identified org.apache.catalina.valves.AccessLogValve is used to log http access logs.

If you want to delete the access log file older than 30 days, this option can be used https://stackoverflow.com/a/57826692/10055162.

Navigate to <IS-HOME>/repository/resources/conf/templates/repository/conf/carbon.xml.j2 and add property maxDays="30" to AccessLogValve as follows. Then restart the server.

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="${carbon.home}/repository/logs"
                       prefix="http_access_" suffix=".log" pattern="{{http_access_log.pattern}}"  maxDays="30" />

Since these configs adding is not templated, you can't do the configuration via deployment.toml

More info about the property: https://tomcat.apache.org/tomcat-7.0-doc/config/valve.html

CodePudding user response:

I would suggest you to use Apinizer instead of Wso2 if you do not want to deal this kind of problems. In Apinizer, all retentions can be set from management forms without any script or language, and for analytics since it uses elasticsearch all lifecycle management can be handled with lifecycle management forms (btw you do not have to know anything about ES, it handles all kind of ES operations from its forms)

  • Related