- Logging inSpring can be done in following ways
- Java util logging
- Commons-logging
- Log4j
- Logback
- Log4j2
- jBoss Logging
- SLF4J
- A facade for other logging providers.
- Logging using MDC(Mapped Dynamic Context)
- MDC is used to log apps in a way that complex distributed apps can be audited and debuggedeasily.
- To print a MDC value in logs use “%X{key}”
- For example “%X{CorrelationId}”
- To print all variables in Mapped Dynamic Context use “%X”.
- Logging in specific config file
- We use logging file name = myapp.log
- We use logging configuration file - logback.xml
- We can reuse logging resources xml
- We can define properties in xml.
- Using log back spring extension
- Used logging with different profiles
- Create File logback-{profile}.xml
- Add XML properties to this file.
- Refer to spring docs For adding properties
- Using log4J
- Add dependency in project management tool like Maven/Gradle.
- Best Practices
- Use correlationID/TrackingID with MDC.
- Don’t log sensitive data.
- Check for isDebugEnabled()/isTrackEnabled()
- Logs statement is executed even if they are disabled(Just not printed).
- Structured Logging.
- Elastic log stash and Kibana
- Elastic Search,Fluentd and Kibana.
- Distributed Tracing-Spring Cloud Sluth
- Helps to trace logs from one micro service to another micro service
- ELK/EFK stack
- EFK Stack
- The EFK Stack is a collection of three open source products
- Elastic Search
- It is used for storing logs(Log Lake).
- Elastic Search is deployed using Stateful Set.
- Fluentd
- For shipping, Processing and storing logs.
- Ships log from container to Elastic search database
- FluentD is deployed using Daemon Set
- Kibana
- Visualisation tool to monitor logs.
- Deployment is done using Kibana
- EFK stack provides centralised logging in order to identify problems with services or applications.
- It allows you to search all the logs in a single place.
- EFK can be set up in AWS EKS cluster.
- ELK Stack used for anlysing logs is described in more detail here
No comments:
Post a Comment