How to log messages to a log file in a specific path from a bash script
- by Erik
How do you log messages to a log file in a specific path from a bash script?
A naive implementation would be commands like:
echo My message >>/my/custom/path/to/my_script.log
But this probably has many disadvantages (no log rotation for example).
I could use the 'logger' command, but it does not support logs in custom paths as far as I know and is not easy to configure if you have lots of bash scripts that could use a custom log file.
In a scripting language like Ruby all this is quite easy: https://github.com/rudionrails/yell/wiki/101-the-datefile-adapter
I could also make my own logger command based on this ruby library and call it from my bash scripts, but I guess there is already a well known solution that provides similar behavior for shell scripts?