# How to log cron jobs?

To log cron jobs, you can use the following steps:

## Redirect the output

You can redirect the output of the cron job to a log file by adding the following line at the end of the cron job command: **`>> /path/to/logfile 2>&1`**. This will redirect both the standard output and standard error streams to the specified log file.

```bash
* * * * * myjob.sh **>> /path/to/logfile 2>&1**
```

## Set up log rotation

If you want to keep your log file from growing too large, you can set up log rotation using a tool like logrotate. This will automatically rotate your log files based on size or time interval.

## Use a logging tool

Another option is to use a logging tool like `syslog-ng` or `rsyslog` to log your cron jobs. These tools can be configured to store logs in a central location and provide advanced features such as filtering and alerting.

## Monitor logs

Once you have set up logging, it's important to monitor the logs to ensure that your cron jobs are running as expected. You can use tools like [Better Uptime](https://betterstack.com/better-uptime) to monitor your logs and alert you if any errors or warnings are detected

[info]
## 🔭 Want to get alerted when your Cron doesn’t run correctly?
Go to [Better Stack](https://betterstack.com/uptime/) and start monitoring in 5 minutes.
[/info]

By following these steps, you can effectively log your cron jobs and ensure that your system is running smoothly.

[ad-logs]