I'm building a NodeJS application and trying to use the Elastic Stack to collect the logs. The logs I want are:
- Error logs
- Application logs like, user logged in, user performed this task, system performed this task, etc
Now my application is hosted in Kubernetes and I deployed the Elastic Stack also to the same GKE cluster. Now I'm new to Elastic Stack. I have a small idea that we have to send data to logstash and it sends to the elastic search. Then we can visualize in Kibana. I tried to follow several tutorials but still don't have a solid idea on how to do this. To connect my app to the stack. So, may I please know...
- to where in the stack (elastic search, logstash or filebeat) I should send the logs,
- how to send the logs from a NodeJS app to an elastic stack hosted in the same Kubernetes cluster,
- what tools I should use to do this job.
Thanks in advance ????
Update: Now I managed to write the logs to a file in the node app using winston. So it creates error.log
and combined.log
in the app root directory:
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [
//
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' })
]
});
(According to my docker file WORKDIR /usr/src/app
):
FROM node:lts as build-stage
WORKDIR /usr/src/app
ENV NPM_CONFIG_LOGLEVEL warn
COPY package.json package.json
COPY yarn.lock yarn.lock
RUN yarn install
COPY . .
RUN yarn build
RUN yarn install --production
FROM node:lts
WORKDIR /usr/src/app
COPY --from=build-stage /usr/src/app /usr/src/app
CMD yarn serve
EXPOSE 8000
Now I have installed filebat but it takes all the other logs from Nginx and stuff but not this. How to tell it to get exactly these two files?