NestJS sample app that uses Log4js logger with Logstash
- Run
docker-compose upto start the Logstash container. - Run
npm run startto start the NestJS app.
- Create a new project using Nest CLI by running
nest new nestjs-log4js-logstash - Add sample logs in
src/app.controller.tsandsrc/app.service.tsusing Nest Logger - Install Nest configuration module to configure application properties by running
npm i --save @nestjs/config - Install log4js by running
npm i @nestx-log4js/core - Install log4js-logstash-tcp by running
npm i log4js-logstash-tcp - Update
src/app.module.tsto configureLog4jsModulewith 2 appenders, logstash and stdout - Update
src/main.tsto useLog4jsLoggeras app logger - Configure ELK stack using docker-compose
- add
docker-compose.ymlfile with container configurations for ELK - under
logstashdirectory, add config files for logstash
- add
Once app and containers are running, you can see startup logs both in console and in Kibana by navigating to http://localhost:5601. Index is automatically created with logstash- prefix in the name. You can locate index under Management > Stack Management > Data > Index Management. Create index pattern as logstash-* under Management > Stack Management > Kibana > Index Patterns and view your logs sent from the application under Analytics > Discover specifying index pattern you created, that is logstash-*.