Error Logging: Record Errors
Log errors. To files. To syslog. Track them.
Here's the thing: Log errors. Track them. Fix them.
Log to File
log_error() {
echo "$(date): ERROR: $1" >> error.log
}
log_error "Something failed"
My take: Log to file. Track errors.
Log to syslog
logger "Error message"
My take: logger sends to syslog. Use it.
Common Patterns
Log Function
log() {
local level=$1
shift
echo "$(date): [$level] $*" >> app.log
}
log ERROR "Something failed"
What's Next?
Now that you understand error logging, let's talk about Debugging Techniques.
Personal note: Error logging seemed unnecessary at first. Then I needed it. Now I log everything. It helps. Do it.