Remote logging with rsyslog, php and agavi

When I tried to get rsyslog running with php I didn't face much problems. Anyways I want to share some things I noticed while getting it to work.

First of all ubuntu uses rsyslog already. Just a simple

# apt-get install rsyslog-mysql

and all syslog messages went directly into the database "syslog". Configure /etc/rsyslog.d/mysql.conf to insert this information into a remote machine.

Now let's get to php. You have the option to set:


This however does log all messages with

php: whatever the issue or error is

If you want to replace "php" with a custom message, you have to call

openlog('myapp', LOG_PID | LOG_ODELAY, LOG_USER);

before any error happens. Because LOG_ODELAY is given, it won't connect to syslog unless any error happens, so one should be save to put this call at the top of your dispatcher file.

The final log message will look like that (254 is the process id):

Sep 26 13:39:44 root-server myapp[254]: the issue or error

Finally I wanted to log all messages created by agavi's logging system. Since I didn't found an existing

AgaviSyslogLoggerAppender, I wrote one and put it up on a github-gist.

Have fun logging!

In agavi, myquests, php, ubuntu by @ 26 Sep 2011

comments powered by Disqus

Recent Files


Recent Dev-Articles

Read recently