I have a log rotation created in the cron job as below. The logs are sent to the path persistant volume /data/db/.mongodb/mongosh. How to redirect the logs to /var/logs/mongodb? I also want to add a timestamp to the log.
apiVersion: batch/v1
kind: CronJob
metadata:
name: mongodb-logrotate
namespace: ciam-dev
annotations:
application_service: “mongo-service”
spoc: “xxxxxx - xxxxxx”
spec:
schedule: “0 13 * * *” # Runs at 1 UTC everyday
jobTemplate:
spec:
template:
spec:
containers:
- name: logrotate
image: xxxxxxxxxxx.dkr.ecr.eu-north-1.amazonaws.com/mongo:8.0.0
command: [“/bin/sh”, “-c”]
args:
- “mongosh -u xxxxx -p xxxxx --eval ‘db.adminCommand({ logRotate: 1 })’ --host mongodb --port 27017”
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
configMapKeyRef:
key: rootusername
name: mongodb-config
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-secret
key: mongodb-root-password
restartPolicy: OnFailure