Bug 19652 - REST API: Log request and response content
Summary: REST API: Log request and response content
Status: BLOCKED
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Lari Taskula
QA Contact:
URL:
Keywords:
Depends on: 18206
Blocks:
  Show dependency treegraph
 
Reported: 2017-11-20 11:59 UTC by Lari Taskula
Modified: 2020-01-11 19:41 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 19652: Debug-level logging for response JSON (3.48 KB, patch)
2017-11-20 11:59 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 19652: Debug-level logging for response JSON (3.42 KB, patch)
2017-11-20 12:18 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 19652: REST API: Log request and response content (5.51 KB, patch)
2017-11-22 08:21 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 19652: REST API: Log request and response content (5.03 KB, patch)
2017-11-22 08:35 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 19652: REST API: Log request and response content (5.08 KB, patch)
2019-02-26 13:05 UTC, Josef Moravec
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lari Taskula 2017-11-20 11:59:22 UTC
Log response JSON in REST API log.
Comment 1 Lari Taskula 2017-11-20 11:59:58 UTC Comment hidden (obsolete)
Comment 2 Lari Taskula 2017-11-20 12:18:47 UTC Comment hidden (obsolete)
Comment 3 Lari Taskula 2017-11-20 12:22:29 UTC
Test plan step 2 example conf (in your log4perl.conf file):

log4perl.logger.rest = DEBUG, REST
log4perl.appender.REST=Log::Log4perl::Appender::File
log4perl.appender.REST.filename=/home/koha/koha-dev/var/log/rest.log
log4perl.appender.REST.create_at_logtime=true
log4perl.appender.REST.syswrite=true
log4perl.appender.REST.recreate=true
log4perl.appender.REST.mode=append
log4perl.appender.REST.layout=PatternLayout
log4perl.appender.REST.layout.ConversionPattern=[%d] [%p] %m %l %n
log4perl.appender.REST.utf8=1
Comment 4 Lari Taskula 2017-11-22 08:21:41 UTC Comment hidden (obsolete)
Comment 5 Lari Taskula 2017-11-22 08:35:36 UTC
Created attachment 69267 [details] [review]
Bug 19652: REST API: Log request and response content

This patch adds request and response logger to REST API. It is useful for viewing
parameters that came within the request, and the content that is about to be
rendered back.

To test:
1. prove t/db_dependent/api/v1.t
2. Configure log4perl configuration file for REST API and set log level to DEBUG
3. Make any request to existing REST API endpoint
4. Observe response JSON in your log file

Example configuration:
log4perl.logger.rest = DEBUG, REST
log4perl.appender.REST=Log::Log4perl::Appender::File
log4perl.appender.REST.filename=/home/koha/koha-dev/var/log/rest.log
log4perl.appender.REST.create_at_logtime=true
log4perl.appender.REST.syswrite=true
log4perl.appender.REST.recreate=true
log4perl.appender.REST.mode=append
log4perl.appender.REST.layout=PatternLayout
log4perl.appender.REST.layout.ConversionPattern=[%d] [%p] %m %l %n
log4perl.appender.REST.utf8=1
Comment 6 Josef Moravec 2019-02-26 13:05:26 UTC
Created attachment 85718 [details] [review]
Bug 19652: REST API: Log request and response content

This patch adds request and response logger to REST API. It is useful for viewing
parameters that came within the request, and the content that is about to be
rendered back.

To test:
1. prove t/db_dependent/api/v1.t
2. Configure log4perl configuration file for REST API and set log level to DEBUG
3. Make any request to existing REST API endpoint
4. Observe response JSON in your log file

Example configuration:
log4perl.logger.rest = DEBUG, REST
log4perl.appender.REST=Log::Log4perl::Appender::File
log4perl.appender.REST.filename=/home/koha/koha-dev/var/log/rest.log
log4perl.appender.REST.create_at_logtime=true
log4perl.appender.REST.syswrite=true
log4perl.appender.REST.recreate=true
log4perl.appender.REST.mode=append
log4perl.appender.REST.layout=PatternLayout
log4perl.appender.REST.layout.ConversionPattern=[%d] [%p] %m %l %n
log4perl.appender.REST.utf8=1
Comment 7 Josef Moravec 2019-02-26 13:05:46 UTC
Just rebased on top of dependency tree
Comment 8 Johanna Räisä 2019-04-17 07:46:55 UTC
This patch doesn't apply. Tested on master.
Comment 9 Johanna Räisä 2019-04-17 07:53:29 UTC
Here is the fail message.

Applying: Bug 19652: REST API: Log request and response content
error: sha1 information is lacking or useless (Koha/REST/V1.pm).
error: could not build fake ancestor
Patch failed at 0001 Bug 19652: REST API: Log request and response content
Comment 10 Johanna Räisä 2019-04-17 09:39:27 UTC
Missed the depedency, will try again.
Comment 11 Johanna Räisä 2019-04-18 09:06:56 UTC
This patch fails to the first point. 

# Subtest: default_exception_handling() tests
    1..5
    # Subtest: Mojo::Exception
        1..4
        ok 1 - GET /default_exception_handling/mojo
        ok 2 - 500 Internal Server Error
        ok 3 - exact match for JSON Pointer "/error"
        # Looks like you planned 4 tests but ran 3.
    not ok 1 - Mojo::Exception
    #   Failed test 'Mojo::Exception'

Tried to continue anyhow but the rest.log file wasn't created. Not sure if the logging suppose to write individual files, seemed that all warnings went to koha-error_log file.