How to set up a proper logger in Symfony2

Properly setting up a logging system for your application is essential for its maintainability, debugging and monitoring.

That being said, what we ideally want in a logging system is the following:

  • Only log our application messages, don’t log symphony stuff;
  • Log to a different file per environment (dev.log, test.log, prod.log);
  • Log to the console, when we run the app through the command line. This way we see feedback immediately, we don’t need to have another window open with tail -f dev.log. With this we can also automate the feedback the app gives back tot he user;
  • Also log specific jobs to a specific file, so we have a log per job;
  • On Production it should also send us an email if something goes wrong.

Continue reading “How to set up a proper logger in Symfony2”

Logging shell scripts

I read a lot of info from here.

However, I didn’t quite understood it, so I tried it out.

I made a small script, and made it run in several ways:

#!/bin/bash
COUNT=0
while [[ $COUNT -lt 10 ]]; do
ls -l /tmp
ls -l /non_existing_folder
sleep 5
let COUNT=$COUNT+1
done

This just shows stdout and stderr on screen:

$ ./out.tst.sh
total 0
ls: cannot access /non_existing_folder: No such file or directory
total 0
ls: cannot access /non_existing_folder: No such file or directory
total 0

This resulted in stdout being appended to the file, but stderr beng shown on screen:

$ ./out.tst.sh >> out.tst.log
ls: cannot access /non_existing_folder: No such file or directory
ls: cannot access /non_existing_folder: No such file or directory
ls: cannot access /non_existing_folder: No such file or directory

This resulted in all output being sent to the file, overwriting the old file:

./out.tst.sh &> out.tst.log
^C

This resulted in all output being appended to the file and the process being sent to the background:

./out.tst.sh &>> out.tst.log &
[1] 4662

This resulted in having stdout in one file, stderr in another one, and the process being sent to the background:

./out.tst.sh 1>> out.tst.ok.log 2>> out.tst.err.log &
[1] 4705