lwan icon indicating copy to clipboard operation
lwan copied to clipboard

Add functionality: log messages to a file ?

Open 0x003e opened this issue 8 years ago • 10 comments

Hi @lpereira ,

Do you think create a "log file" functonality (release and debug) is a good idea ? to write on a file (specified in .conf) all messages of this flowing functions:

  • lwan_status_info
  • lwan_status_warning
  • lwan_status_error
  • lwan_status_perror
  • lwan_status_critical
  • lwan_status_critical_perror
  • lwan_status_debug

I can implement it with a pull request.

0x003e avatar Aug 05 '16 13:08 0x003e

To that I need to remove each

#ifdef NDEBUG

in the source code.

0x003e avatar Aug 05 '16 13:08 0x003e

Logging is indeed important, but it has to be done carefully as to not impact performance that much. I've been postponing this since the project started since I haven't found yet a way I'm comfortable with.

Do you have anything in mind?

lpereira avatar Aug 05 '16 18:08 lpereira

I began implement this functionality:

Log sample file:

log_file_sample

Errors handling:

log_file_error_directory_not_exist

This functionality can be deactivate if neither file are specified in conf file

However, it remains for me to do some benchmark to evaluate performance impact and optimize syscall when the buffer are flushed...

0x003e avatar Aug 05 '16 19:08 0x003e

Hm, I'm not sure if I like Lwan writing directly to a file. I've been more keen to implement logging using the same approach as Varnish rather than files.

lpereira avatar Aug 05 '16 20:08 lpereira

You are right:

GET 100.html 5M request 1K connexions:

  • with log disabled ~312 000 request/s
  • with log enabled ~100 000 request/s
  • redirect stdout to a file ~110 000 request/s

conclusion: log file it's not the best way.

I've been more keen to implement logging using the same approach as Varnish rather than files.

Like this ?: https://github.com/varnishcache/varnish-cache/blob/a50c99f6b3883d1a58cedfe26511bfc0d30d50bb/bin/varnishtest/vtc_log.c

0x003e avatar Aug 05 '16 21:08 0x003e

Like this: https://www.varnish-cache.org/docs/trunk/reference/vsm.html

lpereira avatar Aug 05 '16 21:08 lpereira

Thank's However, for the moment I not completely understand how Varnish export the log message stored in shared memory: https://github.com/varnishcache/varnish-cache/blob/a50c99f6b3883d1a58cedfe26511bfc0d30d50bb/lib/libvarnishapi/vsm.c#L215

I fond this sample: https://github.com/rohitsinha54/shared-memory-producer-consumer/blob/master/prodcon.c.

What do you think of this @lpereira ?: lwan server is a producer and a another process is a consumer. The another process that will wait the log message send by lwan server in a shared memory, and write the log message to a file ?

0x003e avatar Aug 06 '16 00:08 0x003e

That's the idea, @0x003e. In fact, if we could get the SHM format and protocol the same as Varnish's, then all the tools developed for Varnish can be used as well with little to no modification.

lpereira avatar Aug 07 '16 02:08 lpereira

I made a change where it logs 4xx and 5xx as warnings, and leaves everything else fast and unlogged. I like it because I can now see if there's problems with my site, like if I'm missing files, or if one of my custom handlers are failing, or a hacker is trying to probe my server.

I haven't benchmarked this change at all yet, but it should still run just as fast for 2xx and 3xx. I'm willing to make this an actual config option if anyone wants this ability too.

This project is amazing, I really like being able to extend it like this because the code is that simple.

mxh69420 avatar May 06 '20 00:05 mxh69420

Good to know it's working well for you, @samiam308!

lpereira avatar May 06 '20 18:05 lpereira