Knowing how to write error log to files is an important troubleshooting step you can take to debug your system.
For example, if you contact InMotion Hosting support about an issue happening on your server, the support technicians will check error logs to see if there is an identifiable issue happening in the back end. A random-seeming server error can be difficult to sniff out without the error reported.
If you are running any kind of web server, you must develop a comfort with your log files in addition to the common configuration files.
Checking and writing system errors from log files is an ideal way to troubleshoot your cloud server.
You will need write access to files in your server to accomplish the steps in this article. If you are using your default user, you should already have write access. If you want to write to files outside of your home directory you will need to invoke super user privileges with sudo.
However, before contacting support, you can locate and track these error logs yourself. That way, if you need to contact support, you can use the steps in this article to capture, or write, those errors into a file. This way, you can share the file (or just the log output) with your support agent to help more quickly find a solution.
Kinds of Error Logs
There are many different kinds of log files in your system. The good thing about knowing where the error logs are located is that it will help you diagnose all kinds of system issues.
- FTP
- Apache
- Nginx
- SSH
- And many more
Different operating systems save log files in slightly different locations. Always check your operating system documentation to make sure you have the right file locations.
How To Write Error Log To File
In order to capture system messages, you can use “greater than” symbol >
to pipe the error log into a file. And further, use the tail -f
command to watch the file for new errors.
The command example below will “tail” a chosen log file and write the result (>
) to a file in your home directory (~
) called log.txt.
tail -f <log file> > ~/log.txt
Please note, depending on your user level privileges you might need to start this command with “sudo” to invoke “super user” level access.
The result of this command will be the creation of the log.txt file and any errors that occurred while the command was in operation.
You are best advised to start this command before triggering the action that leads to the error. That way, it is most likely you will capture any relevant errors.
Once you have stopped the operation, you can open the log file in your favorite text editor.
Learning how to track and write error logs to files is an easy and important troubleshooting procedure that will help you master your system admin skills.
Continue to build up your skills with these articles:
- How to Secure Your Cloud Server Hosting
- How to Re-OS Your Cloud Server in AMP
- How to Manage Your Cloud Server
Be sure to let us know below if you have any comments or questions or can help improve this article. Learn more from our Cloud Server Hosting Product Guide.
If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.
CentOS, Debian, or Ubuntu No Bloatware SSH and Root Access