LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub

Logging

Logging is very important in microservices architecture as logs must be aggregated in order to trace all the activities of a particular request from a consumer. We are using ELK stack for logging. In production in Kubernetes cluster, there are various options for logging and we may replace Logstash with Fluentd. In this turorial, Elasticsearch, Logstash and Kibana are all started in the same docker-compose.yml.

In order for the example-petstore container to forward log files to ELK, we need to set up log driver on the application container to forward logs to Logstash and then to ElasticSearch.

Bofore taking any action, let’s first kill the petstore docker container if it is still running.

For demo purposes, ELK will be started with a docker-compose locally. There is a compose file available in light-docker called docker-compose-logging.yml

Please note that ElasticSearch has some requirements in memory, file handlers etc. to start up. On my Linux desktop, I need to run the following.

sudo sysctl -w vm.max_map_count=262144

The following is the steps to start ELK locally.

cd ~/networknt/light-docker
docker-compose -f docker-compose-logging.yml up

You can go to http://localhost:9200 to confirm that ElasticSearch is running.

And you can go to http://localhost:5601 to confirm that Kibana is running.

With ELK running, here is the command line to start the petstore docker container.

Start Container with Docker

export LOGSTASH_ADDRESS=$(docker inspect --format '{{ .NetworkSettings.Networks.localnet.IPAddress }}' lightdocker_logstash_1)
docker run -d -p 8443:8443 --network=localnet --log-driver=gelf --log-opt gelf-address=udp://$LOGSTASH_ADDRESS:12201 --log-opt tag="petstore" --log-opt env=dev networknt/com.networknt.petstore-1.0.1

Now your petstore is up and running and all logs have sent to the Logstash and then ElasticSearch. Let’s go to the Kibana to see if our logs can be viewed there.

http://localhost:5601/

Just leave the default Index pattern (logstash-*) and select @timestamp for Time Filter field name then click Create button.

Now you can see the logs if you hit Discover menu.

Start Container with Compose

First let’s stop the docker container by finding the container id first with “docker ps” and then issue a docker stop {container id}

As we have exported the LOGSTASH_ADDRESS in the previous step, don’t need to do that again. If you have skipped the previous step, then you need to do the export.

export LOGSTASH_ADDRESS=$(docker inspect --format '{{ .NetworkSettings.Networks.localnet.IPAddress }}' lightdocker_logstash_1)

Once the environment variable is set, let’s start the server with docker-compose.

cd ~/networknt/light-config-test/light-example-4j/rest/swagger/petstore/logging
docker-compose up

Once the docker-compose is up, you can goto Kibana to view the logs.

http://localhost:5601/

As you can see this time each log entry has tag as “petstore-compose” to indicate that it is collected from the docker-compose.

Here is one example entry.

March 10th 2018, 17:44:24.714	source_host:172.18.0.1 level:6 created:March 10th 2018, 17:44:22.136 message:Https Server started on ip:0.0.0.0 Port:8443 version:1.1 command:/bin/sh -c java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar image_name:networknt/com.networknt.petstore-1.0.1 @timestamp:March 10th 2018, 17:44:24.714 container_name:logging_petstore_1 host:joy @version:1 tag:petstore-compose image_id:sha256:8013f49a287c998886f5fdc65c18bd62a4674d06bd4d7d111345272f716b5fe1 container_id:c3fba2f3c9f3900d75896ad91f7b0fd2a18757b411cf2f7462b41fdb031ed165 _id:AWISFigbs8Bk8xA0uV2x _type:logs _index:logstash-2018.03.10 _score: -

Above steps are just demos that give you an idea how centralized logging looks like. They are not supposed to be used for production. Production with Kubernetes will be covered in another tutorial.

In the next step, we are going to enable metrics to InfluxDB.

  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Logging” was last updated: July 5, 2021: fixes #275 checked and corrected grammar/spelling for majority of pages (#276) (b3bbb7b)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute