NestJS sample app that uses Log4js logger with Logstash
- Run
docker-compose up
to start the Logstash container. - Run
npm run start
to 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.ts
andsrc/app.service.ts
using 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.ts
to configureLog4jsModule
with 2 appenders, logstash and stdout - Update
src/main.ts
to useLog4jsLogger
as app logger - Configure ELK stack using docker-compose
- add
docker-compose.yml
file with container configurations for ELK - under
logstash
directory, 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-*
.