VirtualBox

Ignore:
Timestamp:
Oct 22, 2020 11:36:16 PM (4 years ago)
Author:
vboxsync
Message:

IPRT/rest: bugref:9167 - Add release logging for REST operations.
Request are logged at level 5, and responses at level 7, so they are
not on by default. The format is a bit ad-hoc, but all the essential
information should be there. It's mostly done in base classes except
for request bodies (it can probably be done in the base class too, but
would require more runtime logic, while here we can only generate them
as needed).

Location:
trunk/src/VBox/Runtime/common/rest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/rest/RTCRestClientRequestBase.cpp

    r82968 r86681  
    3434#include <iprt/assert.h>
    3535#include <iprt/err.h>
     36#include <iprt/log.h>
    3637#include <iprt/cpp/restarray.h>
    3738#include <iprt/cpp/reststringmap.h>
     
    100101                     VERR_INTERNAL_ERROR_3);
    101102        AssertMsgReturn(a_paPathParamStates[i].pObj != NULL,
    102                         ("Path parameter '%s' is not set!\n", a_paPathParams[i].pszName),
     103                        ("%s: Path parameter '%s' is not set!\n",
     104                         getOperationName(), a_paPathParams[i].pszName),
    103105                        VERR_REST_PATH_PARAMETER_NOT_SET);
    104106        AssertMsgReturn(m_fIsSet & RT_BIT_64(a_paPathParams[i].iBitNo),
    105                         ("Path parameter '%s' is not set!\n", a_paPathParams[i].pszName),
     107                        ("%s: Path parameter '%s' is not set!\n",
     108                         getOperationName(), a_paPathParams[i].pszName),
    106109                        VERR_REST_PATH_PARAMETER_NOT_SET);
    107110
     
    109112        rc = a_paPathParamStates[i].pObj->toString(&strPathParam, a_paPathParams[i].fFlags);
    110113        AssertRCReturn(rc, rc);
     114
     115        LogRel5(("> %s: /%s = %s\n",
     116                 getOperationName(), a_paPathParams[i].pszName, strPathParam.c_str()));
    111117
    112118        RTCString strTmpVal;
     
    141147        {
    142148            AssertMsgReturn(a_papQueryParamObjs[i] != NULL,
    143                             ("Required query parameter '%s' is not set!\n", a_paQueryParams[i].pszName),
     149                            ("%s: Required query parameter '%s' is not set!\n",
     150                             getOperationName(), a_paQueryParams[i].pszName),
    144151                            VERR_REST_REQUIRED_QUERY_PARAMETER_NOT_SET);
    145152            AssertMsgReturn(m_fIsSet & RT_BIT_64(a_paQueryParams[i].iBitNo),
    146                             ("Required query parameter '%s' is not set!\n", a_paQueryParams[i].pszName),
     153                            ("%s: Required query parameter '%s' is not set!\n",
     154                             getOperationName(), a_paQueryParams[i].pszName),
    147155                            VERR_REST_REQUIRED_QUERY_PARAMETER_NOT_SET);
    148156
     
    155163                rc = a_pStrQuery->appendPrintfNoThrow("%c%RMpa=%RMpa", chSep, a_paQueryParams[i].pszName, strTmpVal.c_str());
    156164                AssertRCReturn(rc, rc);
     165
     166                LogRel5(("> %s: ?%s = %s\n",
     167                         getOperationName(), a_paQueryParams[i].pszName, strTmpVal.c_str()));
    157168
    158169                chSep = '&';
     
    175186                    AssertRCReturn(rc, rc);
    176187
     188                    LogRel5(("> %s: ?%s[%d] = %s\n",
     189                             getOperationName(), a_paQueryParams[i].pszName, j, strTmpVal.c_str()));
     190
    177191                    chSep = '&';
    178192                }
     
    198212        {
    199213            AssertMsgReturn(m_fIsSet & RT_BIT_64(a_paHeaderParams[i].iBitNo),
    200                             ("Required header parameter '%s' is not set!\n", a_paHeaderParams[i].pszName),
     214                            ("%s: Required header parameter '%s' is not set!\n",
     215                             getOperationName(), a_paHeaderParams[i].pszName),
    201216                            VERR_REST_REQUIRED_HEADER_PARAMETER_NOT_SET);
    202217            AssertMsgReturn(a_papHeaderParamObjs[i] != NULL,
    203                             ("Required header parameter '%s' is not set!\n", a_paHeaderParams[i].pszName),
     218                            ("Required header parameter '%s' is not set!\n",
     219                             getOperationName(), a_paHeaderParams[i].pszName),
    204220                            VERR_REST_REQUIRED_HEADER_PARAMETER_NOT_SET);
    205221
     
    212228                                     RTHTTPADDHDR_F_BACK);
    213229                AssertRCReturn(rc, rc);
     230
     231                LogRel5(("> %s: :%s = %s\n",
     232                         getOperationName(), a_paHeaderParams[i].pszName, strTmpVal.c_str()));
    214233            }
    215234            else if (!a_papHeaderParamObjs[i]->isNull())
     
    238257                                         RTHTTPADDHDR_F_BACK);
    239258                    AssertRCReturn(rc, rc);
     259
     260                    LogRel5(("> %s: :%s = %s\n",
     261                             getOperationName(), strTmpName.c_str(), strTmpVal.c_str()));
    240262                }
    241263            }
  • trunk/src/VBox/Runtime/common/rest/RTCRestClientResponseBase.cpp

    r82968 r86681  
    3434#include <iprt/ctype.h>
    3535#include <iprt/err.h>
     36#include <iprt/log.h>
    3637#include <iprt/cpp/reststringmap.h>
    3738
     
    255256        if (RT_SUCCESS(rc))
    256257        {
     258            LogRel7(("< %s: :%s = %s\n",
     259                     getOperationName(), a_pszErrorTag, strValue.c_str()));
     260
    257261            /*
    258262             * Try deserialize it.
     
    270274    else
    271275    {
    272         addError(rc, "Error %Rrc validating value necoding of header field '%s': %.*Rhxs",
     276        addError(rc, "Error %Rrc validating value encoding of header field '%s': %.*Rhxs",
    273277                 rc, a_pszErrorTag, a_cchValue, a_pchValue);
    274278        rc = VINF_SUCCESS; /* ignore */
     
    303307                if (RT_SUCCESS(rc))
    304308                {
     309                    LogRel7(("< %s: :%s%.*s = %s\n",
     310                             getOperationName(), a_pszErrorTag, a_cchField, a_pchField,  strValue.c_str()));
     311
    305312                    /*
    306313                     * Try deserialize the value.
     
    343350        if (RT_SUCCESS(rc))
    344351        {
     352            if (LogRelIs7Enabled())
     353            {
     354                /* skip m_ or m_p prefix */
     355                const char *pszName = a_pszBodyName;
     356                if (pszName[0] == 'm' && pszName[1] == '_')
     357                {
     358                    if (pszName[2] == 'p')
     359                        pszName += 3;
     360                    else
     361                        pszName += 2;
     362                }
     363
     364                LogRel7(("< %s: %d: %s = %.*s\n",
     365                         getOperationName(), m_rcHttp, pszName, a_cbData, a_pchData));
     366            }
     367
    345368            RTERRINFOSTATIC ErrInfo;
    346369            RTJSONVAL hValue;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette