I am using YAJL to read and write Json requests and replies in cgi programs as in following;
How can I make a log file of Json requests and responses?
Thank's a lot
Dario
ctl-opt dftactgrp(*no) actgrp('TEST') decedit('0.')
bnddir('YAJL':'QC2LE')
option(*srcstmt: *nodebugio: *noshowcpy);
/include YAJL/qrpglesrc,YAJL_H
dcl-s request char(500);
dcl-s errmsg varchar(500);
docNode = yajl_stdin_load_tree(*on: errMsg);
if errMsg <> '';
errMsg = 'json parse: ' + errMsg;
yajl_writeStdout(500: errMsg);
return;
endif;
node = yajl_object_find(docNode: 'request');
if node = *null;
request= 'mandatory';
else;
request= yajl_get_string(node);
endif;
yajl_tree_free(docNode);
yajl_genOpen(*off);
yajl_beginObj();
yajl_addChar('Request is ': request );
yajl_endObj();
yajl_writeStdout(200: errMsg);
yajl_genClose();
return;
How can I make a log file of Json requests and responses?
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: How can I make a log file of Json requests and responses?
If you are on a recent version of YAJL, the yajl_stdin_load_tree subprocedure has a 3rd optional parameter that is an IFS path name that it can save the request to. If that file isn't sufficient and it needs to be in a separate log, you will need to write the data to a temporary file, then read it into your own program and write it to the log from there.
For the response, before you call yajl_writeStdout(), call yajl_saveBuf() to save it to a file or yajl_copyBufStr() to copy it to a string variable and write it to a file yourself.
For the response, before you call yajl_writeStdout(), call yajl_saveBuf() to save it to a file or yajl_copyBufStr() to copy it to a string variable and write it to a file yourself.
- Ticonderogah
- Posts: 3
- Joined: Wed Jul 28, 2021 12:05 pm
Re: How can I make a log file of Json requests and responses?
Scott's first suggestion is the one I like. I save all my JSON request/response payloads in the IFS.