Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality: log messages to a file ? #167

Open
0x003e opened this issue Aug 5, 2016 · 10 comments
Open

Add functionality: log messages to a file ? #167

0x003e opened this issue Aug 5, 2016 · 10 comments

Comments

@0x003e
Copy link
Contributor

0x003e commented Aug 5, 2016

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 0x003e changed the title Add log file functionality ? Add functionality: log messages to a file ? Aug 5, 2016
@0x003e
Copy link
Contributor Author

0x003e commented Aug 5, 2016

To that I need to remove each

#ifdef NDEBUG

in the source code.

@lpereira
Copy link
Owner

lpereira commented Aug 5, 2016

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?

@0x003e
Copy link
Contributor Author

0x003e commented Aug 5, 2016

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...

@lpereira
Copy link
Owner

lpereira commented Aug 5, 2016

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.

@0x003e
Copy link
Contributor Author

0x003e commented Aug 5, 2016

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

@lpereira
Copy link
Owner

lpereira commented Aug 5, 2016

@0x003e
Copy link
Contributor Author

0x003e commented Aug 6, 2016

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 ?

@lpereira
Copy link
Owner

lpereira commented Aug 7, 2016

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.

@mxh69420
Copy link

mxh69420 commented May 6, 2020

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.

@lpereira
Copy link
Owner

lpereira commented May 6, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants