How to log messages to a log file in a specific path from a bash script

Posted by Erik on Stack Overflow See other posts from Stack Overflow or by Erik
Published on 2012-09-25T18:19:45Z Indexed on 2012/09/25 21:37 UTC
Read the original article Hit count: 269

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about bash

Related posts about logging