Issue

  • /var/log/application-name is to go
  • logrotate can be useful
  • Should consider permission of that directory

Solution

Should I save application log files in /var/log dir? by Phind

Yes, you should save application log files in the /var/log directory. This is a standard location for log files on Unix-like systems, including Linux distributions, which is widely accepted by the community. This directory is intended for log files produced by various system processes, including those of your application.

However, it’s a good practice to create a dedicated subdirectory for your application under /var/log. This is especially useful if your application generates multiple log files or if you have multiple instances of the application running. Having a dedicated directory makes it easier to locate the log files for a specific application instance.

For example, if your application is named myapp, you could create a directory /var/log/myapp and save all your application logs there.

Here’s an example of how you might structure your logs:

/var/log/myapp/
├── myapp.log
└── myapp-error.log

Remember to set appropriate permissions for your application to write to this directory.

Also, consider using tools like logrotate to manage your log files. This tool can automatically rotate, compress, remove, and mail system logs to prevent them from consuming too much disk space.

Finally, if your application is compromised, you may want to mark the log file as append-only. This ensures that even if your application is compromised, it won’t be able to erase past logs, which can be very useful for forensic analysis.

Referenced