I usually don’t keep lighttpd access logs turned on to avoid writing for every read, but there are times when you need to monitor what’s going on, and you’d like to have a high signal-to-noise ratio so it might be convenient to ignore all requests to .gif, .png, .jpg, .css, .ico and other urls on your webserver.
To only log certain files, or to NOT log certain files, you resolve this the same way as you do every other thing in lighttpd… by matching lighttpd variables to regular expressions and applying the settings where they match.
[perl]
# www -> the main website
$HTTP["host"] =~ "^www.yoursite.com$" {
server.document-root = "/var/www/www.yoursite.com"
server.errorlog = "/var/log/lighttpd/www.yoursite.com/error.log"
#Only log non-css and images
<strong>$HTTP["url"] !~ "(.css|.jpg|.gif|.png|.ico)$" {
accesslog.filename = "/var/log/lighttpd/www.yoursite.com/access.log"
}</strong>
}
[/perl]
So in this example, we only log, where the URL doesn’t end with any of the “.css”, “.jpg”, “.gif”, “.png” or “.ico” extensions. We filter those out.
Hope this works for you.
One thought on “How to filter logs in lighttpd”