PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

https://github.com/edlerd/apache2gelf
Markdown | 67 lines | 45 code | 22 blank | 0 comment | 0 complexity | 9c0f9813c6854894f2a0b1d43c80123a MD5 | raw file
  1. apache2gelf
  2. ===========
  3. A set of python scripts to deliver Apache and PHP log files to graylog2. Scripts support the following log files:
  4. * standard Apache 2.2 error log (errorlog2gelf.py);
  5. * custom (but quite close to standard 'combined') Apache access log (accesslog2gelf.py);
  6. * standard PHP error log (phplog2gelf.py).
  7. Requirements:
  8. * python-argparse
  9. * python-graypy (0.2.8+)
  10. Usage example
  11. -------------
  12. For Apache with mod_php:
  13. <VirtualHost *:80>
  14. ServerName example.com
  15. DocumentRoot /var/www/example.com
  16. ErrorLog "|| /path/to/errorlog2gelf.py --vhost example.com"
  17. CustomLog "|| /path/to/accesslog2gelf.py --vhost example.com" "%V %h %u \"%r\" %>s %b \"%{Referer}i\""
  18. php_admin_value error_log "/var/log/php/example.com.php.log"
  19. </VirtualHost>
  20. phplog2gelf.py basically does 'tail -F', so it should be executed separately:
  21. /path/to/phplog2gelf.py --vhost example.com /var/log/php/example.com.php.log
  22. Command line parameters
  23. -----------------------
  24. All scripts understand the following command line parameters:
  25. * `--host` to specify graylog2 server
  26. * `--port` to specify graylog2 GELF port
  27. * `--facility` to specify log facility
  28. * `--vhost` to add an extra field called 'vhost' to all log messages. This allows you to configure per-virtualhost log handlers (on the expense of running N additional processes, of course) and then filter logs in graylog2 accordingly.
  29. accesslog2gelf.py
  30. -----------------
  31. The script has log format hard-coded into it, so if you would like to change the CustomLog fields or resulting log messages, just hack it.
  32. errorlog2gelf.py
  33. ----------------
  34. The script outputs all messages to stdout. This allows you to have a local log file as well (you can only have one ErrorLog parameter in Apache configuration)
  35. phplog2gelf.py
  36. --------------
  37. This script is somewhat different from the previous two. Because there is no way to get log messages from php via pipe, we have to 'tail -F' the log file. The script supports multiline PHP error log messages as well.
  38. You should launch `phplog2gelf.py` separately - just stick it into your rc.local file. If you have a Debian/Ubuntu system you can also use the following *monit* configuration:
  39. check process phplog2gelf_example with pidfile /var/run/phplog2gelf_example.pid
  40. start program = "/sbin/start-stop-daemon --start --pidfile /var/run/phplog2gelf_example.pid --user www-data --chuid www-data --background --make-pidfile --exec /usr/local/sbin/phplog2gelf.py -- --vhost example.com /var/log/php/example.com.php.log"
  41. stop program = "/sbin/start-stop-daemon --stop --pidfile /var/run/phplog2gelf_example.pid --verbose"
  42. Credits
  43. =======
  44. Copyright (c) 2012, Anton Tolchanov
  45. The scripts are licensed under MIT license.