Steve Hu
Steve Hu

Reputation: 388

How do we integrate access log in logback.xml for light-4j app?

How do we integrate the access logs in logback.xml? There is a class AccessLogHandler for this, but it does not implement MiddlewareHandler, so we cannot inject it in handlers.yml. Is there a simple way to log incoming HTTP requests in access.log like spring provides for tomcat?

Upvotes: 0

Views: 201

Answers (1)

Steve Hu
Steve Hu

Reputation: 388

The AccessLogHandler can be put into the handler.yml to change the logging level via the endpoints provided on the fly. You are right that it is not a middleware handler but an endpoint handler.

If you are using light-4j as a monolithic app, then you can enable the audit log with the AuditHandler. It will log all the requests just like the Tomcat into the audit.log by default. The configuration in the logback.xml can be found at https://github.com/networknt/light-example-4j/blob/release/rest/openapi/petstore/src/main/resources/logback.xml#L44 as an example.

If you are using light-4j as a microservices platform, then the above approach is not working. The following three options can be used individually or combined.

  1. Redirect the logs to the ElasticSearch and access them via kibana. If you are using docker-compose/swarm, you can config it in the docker-compose.yml like this

https://github.com/networknt/light-config-test/blob/master/light-oauth2/test-cloud/docker-compose.yml#L25

If you are using Kubernetes or Openshift, please consult the document to redirect the logs to the console.

  1. Enable Metric handler to collect the access information along with other details about the request/response to InfluxDB or Promethus.

https://doc.networknt.com/concern/metrics/ https://doc.networknt.com/concern/prometheus/

  1. Enable Open Tracing with Jaeger or Skywalking for distributed tracing.

https://doc.networknt.com/tutorial/tracing/

Upvotes: 0

Related Questions