12

I'd like to prepend the vhost name in my ErrorLog and then pipe it into a program I wrote.

Is it possible to write Custom Error log format as it is with Access log?

pmaruszczyk
  • 107
  • 5
JohnT
  • 145
  • 1
  • 1
  • 4
  • Depending on your setup, you can have an ErrorLog for each of your virtual hosts. It's not the same as a unified parsable logfile, but it's something. – muffinista May 06 '11 at 16:31

4 Answers4

8

For piping see the ErrorLog directive and Piped Logs official manual entries which explain it pretty well.

Getting a custom error log format is more difficult. You can customize the access log easily with LogFormat but there is nothing built in for modifying the error log format. I did come across CGI::Carp which is a Perl module for outputting to the error log. Finally, there is always modifying the Apache source code directly depending on how badly you want this feature.

uesp
  • 3,384
  • 1
  • 17
  • 16
8

In Apache 2.2 you cannot change the format of error_log easily - see http://httpd.apache.org/docs/2.2/logs.html#errorlog.

Apache 2.4 adds this support. See http://httpd.apache.org/docs/2.4/logs.html#errorlog.

Yishai
  • 81
  • 1
  • 1
6

With Apache 2.4 you can use the ErrorLogFormat directive.

Syntax: ErrorLogFormat [connection|request] format

Simple example

ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"

Example (default format for threaded MPMs)

ErrorLogFormat "[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"

Example (similar to the 2.2.x format)

ErrorLogFormat "[%t] [%l] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"

Advanced example with request/connection log IDs

ErrorLogFormat "[%{uc}t] [%-m:%-l] [R:%L] [C:%{C}L] %7F: %E: %M"
ErrorLogFormat request "[%{uc}t] [R:%L] Request %k on C:%{c}L pid:%P tid:%T"
ErrorLogFormat request "[%{uc}t] [R:%L] UA:'%+{User-Agent}i'"
ErrorLogFormat request "[%{uc}t] [R:%L] Referer:'%+{Referer}i'"
ErrorLogFormat connection "[%{uc}t] [C:%{c}L] local\ %a remote\ %A"

Source: ErrorLogFormat Directive

null
  • 268
  • 3
  • 5
  • Can anyone guess why `%a` would show up blank? It's supposed to be the client IP address. I [posted a question](https://serverfault.com/q/981195/161152) about that. – Bob Stein Aug 29 '19 at 17:25
1

You are probably looking for mod_log_debug.

Scott Pack
  • 14,717
  • 10
  • 51
  • 83
  • While you are correct, it would be preferable to include the essential parts of the answer at the link here, in case the link goes dead or is moved. – HopelessN00b Oct 08 '12 at 01:13