lighttpd forum migration > Separate log files for each vhost. How?

Posted by Evert Meulie
on 20.12.2005 11:44
Hi!

I'm in the process of migrating from Apache2 to Lighttpd. How do I make 
it so that each vhost has its own access/error log?


Regards,
  Evert
Posted by Ryan Schmidt
on 20.12.2005 14:02
Use accesslog.filename or accesslog.use-syslog to set the access log. 
See:

http://lighttpd.net/documentation/accesslog.html

Use server.errorlog or server.errorlog-use-syslog to set the error log. 
See:

http://lighttpd.net/documentation/configuration.html

To use a specific logfile for just one vhost, wrap it in a conditional:

$HTTP["host"] == "www.example.org" {
  server.document-root = "/var/www/servers/www.example.org/pages/"
  accesslog.filename = 
"/var/www/servers/www.example.org/logs/access.log"
  server.errorlog = "/var/www/servers/www.example.org/logs/error.log"
}

There are at least three ways of making this easier if you have very 
many vhosts:

http://blog.lighttpd.net/articles/2005/11/25/simplify-your-configfiles-with-includes
http://lighttpd.net/documentation/simple-vhost.html
http://lighttpd.net/documentation/mysqlvhost.html
Posted by Leafish Dylan
on 18.02.2006 16:10
It would be nice if you could define a pattern for log files. I think 
there's an issue in the bug tracker that suggests this, too.

Ideally, I'd like to have "one evhost pattern to rule them all" and 
avoid adding conditionals for every virtual host to set up logs.
Posted by Rhinofly Yin
on 15.03.2007 12:02
Leafish Dylan wrote:
> It would be nice if you could define a pattern for log files. I think 
> there's an issue in the bug tracker that suggests this, too.
> 
> Ideally, I'd like to have "one evhost pattern to rule them all" and 
> avoid adding conditionals for every virtual host to set up logs.

As you know we wanna to do:
accesslog.filename = "|/usr/sbin/cronolog /opt/log/domais/" + 
evhost.domain + /%Y%m%d.log"

just one accesslog.filename configure line for all virtual host and get 
the access log in they own log directory (or anther split log as you 
wish),but it is sorry that lighttpd no support this yet.

for this purpose,I just write a php script to do it:

use this configure to load it:
accesslog.filename          = "|/opt/sbin/domainlogger.php"

and in the /opt/sbin/domainlogger.php we have this setting:

define("__APP_CRONOLOG_BIN__",'/usr/sbin/cronolog');

define("__APP_CRONOLOG_FORMAT__",'%Y%m/%Y%m%d.log');

define("__APP_CRONOLOG_LOG_BASEDIR__",'/opt/var/lighttpd/logs/domains/');

define("__APP_DEFAULT_DOMAIN_NAME__",'default.domains.com');

and then ,all access log write from lighttpd to domainlogger.php will 
been slipt by the domain name and write in to 
/opt/var/lighttpd/logs/domains/www.thedomain.com/200703/20070315.log .


log line:
61.153.24.15 www.domain1.com - [15/Mar/2007:19:50:36 +0800] "GET 
/danniez/Darling.mp3 HTTP/1.1" 301 0 "-" "NSPlayer/10.0.0.4054 
WMFSDK/10.0"

will write to log file :
/opt/var/lighttpd/logs/domains/www.domain1.com/200703/20070315.log

and :
61.153.24.15 www.domain2.com - [15/Mar/2007:19:50:36 +0800] "GET 
/danniez/Darling.mp3 HTTP/1.1" 301 0 "-" "NSPlayer/10.0.0.4054 
WMFSDK/10.0"

will write to log file :
/opt/var/lighttpd/logs/domains/www.domain2.com/200703/20070315.log

and so on.

Is this what you want?

This is a 3996 byte script and too long to post here.

send a mail to snailfly AT gmail dot com with the subject [lighttpd] to 
me,if you wanna to get this script.

PS: For now you can't split server.errorlog each domain.

Good luck.
Posted by rkg (Guest)
on 24.05.2007 11:11
Evert Meulie wrote:

> I'm in the process of migrating from Apache2 to Lighttpd. How do I make 
> it so that each vhost has its own access/error log?

I've "patched" this problem doing a simple script that daily, before 
processing the statics splits the access.log file per domain (second 
field of each line), after that erases it and sends a HUP signal to the 
lighttpd process (then an it generates again a new access.log).

Enough for me, at this moment... hope that this idea helps someone... 
please introduce patterns at mod_accesslog
Posted by Evert Meulie
on 22.06.2008 11:29
rkg wrote:

> Enough for me, at this moment... hope that this idea helps someone... 
> please introduce patterns at mod_accesslog

A year later now. Have patterns made it yet into mod_accesslog?   ;-)


Greetings,
   Evert