H2o: logging handler

Created on 16 Dec 2017  路  7Comments  路  Source: h2o/h2o

I wrote mruby handler for formatting/controlling access log.
but I need to add mruby-handler-file directive to every tons of path: in h2o conf.

it seems better to allow adding handler to access log directive, and apply every request/response under that scope.

usecase:

  • adding all request header into acccesslog
  • formatting values into json/ltsv etc via handler
  • routing/rotating log file from handler

Most helpful comment

Talked with @Jxck and agreed that it would make sense to have a logging directive that allows us to log all the request headers (possibly concatenated with \n) or response headers.

All 7 comments

hi @Jxck
most of the stuff you mentioned can already be done but might be slightly under documented.
rotating logfiles should done via pipe, i recently tried to improve the docs here a bit:
https://github.com/h2o/h2o/pull/1528

formating the logs via json can already be done via escape: json

definitly logging all headers should be possible but isn't. iirc i once opened a ticket but can't find it right now. currently i do this hack in mruby:

headers = JSON.dump(env.find_all{|k,v| k.start_with?("HTTP_")})
[200, {  "x-fallthru-set-MRB_HEADERS" => headers }, [result]]

and then log via:

access-log: 
  path: /dev/stdout
  format: '{ "requestHeaders": %{MRB_HEADERS}e }'
  escape: json

i dont think your idea of calling mruby code for every call just to tamper with the logs make sense, it would be too expensive.

the point of my issue is not how to write a handler, but how to apply to path.
as I wrote

but I need to add mruby-handler-file directive to every tons of path: in h2o conf.

and

it would be too expensive.

thats depends on usecase.
logger already applies to ever req/res to the server if you enable access-log.

@Jxck it's not really clear to me what the problem is then.

could you maybe explain your current work around and make a sample config on how you think it could be done in a better way?

Talked with @Jxck and agreed that it would make sense to have a logging directive that allows us to log all the request headers (possibly concatenated with \n) or response headers.

@kazuho looking forward to see them !

@kazuho
would be also great if it there would be a json mode as either an object or array of arrays.
i am currently also logging them via mruby, but its ugly as they are not in their original format

any updates ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

utrenkner picture utrenkner  路  5Comments

utrenkner picture utrenkner  路  7Comments

utrenkner picture utrenkner  路  3Comments

voiddeveloper picture voiddeveloper  路  6Comments

chenbd picture chenbd  路  3Comments