Caddy: Allow to skip logging of certain requests

Created on 6 Feb 2018  路  6Comments  路  Source: caddyserver/caddy

General Description

I don't want to whitelist every endpoint, I just want to ignore logging or change logging for specific endpoints.

This might be easily done with something like (edited 2018-02-14):

log access.log {
    not /health
}

1. What version of Caddy are you using (caddy -version)?

v0.10.10

2. What are you trying to do?

Skip logging for /health endpoints

3. What is your entire Caddyfile?

http://*/ {
  log stdout
  errors stderr

  bind 0.0.0.0
}

4. How did you run Caddy (give the full command and describe the execution environment)?

n/a

5. Please paste any relevant HTTP request(s) here.

/health

6. What did you expect to see?

/health log requests cannot be ignored. Log directive only supports base path matching.

7. What did you see instead (give full error messages and/or log)?

Everything is logged, but I have an /health endpoint that I'd like to ignore

8. How can someone who is starting from scratch reproduce the bug as minimally as possible?

Run above caddyfile, and hit /health, try to modify Caddyfile to not log requests to /health

feature request

Most helpful comment

For the record, a more Caddy-omatic way to do this would be:

log access.log {
    not /health
}

or

log access.log {
    except /health
}

All 6 comments

For the record, a more Caddy-omatic way to do this would be:

log access.log {
    not /health
}

or

log access.log {
    except /health
}

@mholt I figured out another way to accomplish this, but it's still not great:

http://*/health {
  bind 0.0.0.0
}

http://*/ {
  log stdout
  errors stderr

  bind 0.0.0.0
}

But this is pretty heavy for anything but this simple example.

I'll take a look at implementing this.

@mholt this seems an easy enough feature to add.

However I鈥檓 wondering does it warrant a little more discussion?

Is not writing entries in the log desirable? I may seems so in the short term but cause numerous issues in the long term. Perhaps a heartbeat url is not logged and the stops working? There is no indication in the logs anything has changed. If a ddos or other attack is attempted on a url that is not logged will this hamper investigation?

I know all of this is individual choice but I thought it was worth a little more discussion

I have an initial implementation it will have the following rules

  log / log.txt {common} {
     except /test
   }

Will not log

  • example.com/test
  • example.com/testing
  • example.com/test.php
  • example.com/test/another/directory.pdf

Will log

  • example.com/atest

Example2

  log / log.txt {common} {
     except /test/
   }

Will not log

  • example.com/test/
  • example.com/test/another/directory.pdf

Will log

  • example.com/test
  • example.com/testing

Questions

  • Is this ok?
  • Should we allow regex in the except value?
  • Should we treat test and test/ the same? Is there an easy way to differntiate if test is a file or a folder? Do we care?
  • I can presume that test means test/ but what about except /test.pdf?

My feeling is that there will need to be no special functionality eg test cannot mean test/. Allow Regex may make it easier to specify specific behaviour.

Thanks Toby, you did great work on this. Sorry I didn't get around to answering your questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wayneashleyberry picture wayneashleyberry  路  3Comments

SteffenDE picture SteffenDE  路  3Comments

whs picture whs  路  3Comments

PhilmacFLy picture PhilmacFLy  路  3Comments

klaasel picture klaasel  路  3Comments