extending logging features
authorVolker Birk <vb@pep.foundation>
Sat, 03 Jun 2017 11:08:14 +0200
changeset 1819b3e57d741b15
parent 1818 48785d8fd123
child 1820 167f2913e770
child 1823 61e7b35398b2
child 1824 def83c456552
extending logging features
src/pEpEngine.c
src/pEpEngine.h
src/pEp_internal.h
     1.1 --- a/src/pEpEngine.c	Fri Jun 02 18:35:21 2017 +0200
     1.2 +++ b/src/pEpEngine.c	Sat Jun 03 11:08:14 2017 +0200
     1.3 @@ -843,6 +843,12 @@
     1.4      session->keep_sync_msg = enable;
     1.5  }
     1.6  
     1.7 +DYNAMIC_API void config_service_log(PEP_SESSION session, bool enable)
     1.8 +{
     1.9 +    assert(session);
    1.10 +    session->service_log = enable;
    1.11 +}
    1.12 +
    1.13  DYNAMIC_API PEP_STATUS log_event(
    1.14          PEP_SESSION session,
    1.15          const char *title,
    1.16 @@ -883,6 +889,24 @@
    1.17      return ERROR(status);
    1.18  }
    1.19  
    1.20 +DYNAMIC_API PEP_STATUS log_service(
    1.21 +        PEP_SESSION session,
    1.22 +        const char *title,
    1.23 +        const char *entity,
    1.24 +        const char *description,
    1.25 +        const char *comment
    1.26 +    )
    1.27 +{
    1.28 +    assert(session);
    1.29 +    if (!session)
    1.30 +        return PEP_ILLEGAL_VALUE;
    1.31 +
    1.32 +    if (session->service_log)
    1.33 +        return log_event(session, title, entity, description, comment);
    1.34 +    else
    1.35 +        return PEP_STATUS_OK;
    1.36 +}
    1.37 +
    1.38  DYNAMIC_API PEP_STATUS trustword(
    1.39              PEP_SESSION session, uint16_t value, const char *lang,
    1.40              char **word, size_t *wsize
    1.41 @@ -1283,8 +1307,6 @@
    1.42                                   const char* old_fpr, 
    1.43                                   const char* new_fpr) 
    1.44  {
    1.45 -    PEP_STATUS status = PEP_STATUS_OK;
    1.46 -    
    1.47      assert(old_fpr);
    1.48      assert(new_fpr);
    1.49      
     2.1 --- a/src/pEpEngine.h	Fri Jun 02 18:35:21 2017 +0200
     2.2 +++ b/src/pEpEngine.h	Sat Jun 03 11:08:14 2017 +0200
     2.3 @@ -202,6 +202,14 @@
     2.4  DYNAMIC_API void config_keep_sync_msg(PEP_SESSION session, bool enable);
     2.5  
     2.6  
     2.7 +// config_service_log() - log more for service purposes
     2.8 +//
     2.9 +//      session (in)    session handle
    2.10 +//      enable (in)     flag if enabled or disabled
    2.11 +
    2.12 +DYNAMIC_API void config_service_log(PEP_SESSION session, bool enable);
    2.13 +
    2.14 +
    2.15  // decrypt_and_verify() - decrypt and/or verify a message
    2.16  //
    2.17  //    parameters:
    2.18 @@ -316,6 +324,17 @@
    2.19      );
    2.20  
    2.21  
    2.22 +DYNAMIC_API PEP_STATUS log_service(PEP_SESSION session, const char *title,
    2.23 +        const char *entity, const char *description, const char *comment);
    2.24 +
    2.25 +#define _STR_(x) #x
    2.26 +#define _D_STR_(x) _STR_(x)
    2.27 +#define S_LINE _D_STR_(__LINE__)
    2.28 +
    2.29 +#define SERVICE_LOG(session, title, entity, desc) \
    2.30 +    log_service((session), (title), (entity), (desc), "service " __FILE__ ":" S_LINE)
    2.31 +
    2.32 +
    2.33  // trustword() - get the corresponding trustword for a 16 bit value
    2.34  //
    2.35  //    parameters:
     3.1 --- a/src/pEp_internal.h	Fri Jun 02 18:35:21 2017 +0200
     3.2 +++ b/src/pEp_internal.h	Sat Jun 03 11:08:14 2017 +0200
     3.3 @@ -162,6 +162,7 @@
     3.4      bool passive_mode;
     3.5      bool unencrypted_subject;
     3.6      bool keep_sync_msg;
     3.7 +    bool service_log;
     3.8      
     3.9  #ifdef DEBUG_ERRORSTACK
    3.10      stringlist_t* errorstack;
    3.11 @@ -183,14 +184,14 @@
    3.12  #else
    3.13  #ifdef ANDROID
    3.14  #include <android/log.h>
    3.15 -#define  LOG_MORE(...)  __android_log_print(ANDROID_LOG_DEBUG, "pEpEngine", " %s :: %s :: %s ", __VA_ARGS__);
    3.16 +#define  LOG_MORE(...)  __android_log_print(ANDROID_LOG_DEBUG, "pEpEngine", " %s :: %s :: %s :: %s ", __VA_ARGS__);
    3.17  #else
    3.18  #include <stdio.h>
    3.19 -#define  LOG_MORE(...)  printf("pEpEngine DEBUG_LOG('%s','%s','%s')\n", __VA_ARGS__);
    3.20 +#define  LOG_MORE(...)  fprintf(stderr, "pEpEngine DEBUG_LOG('%s','%s','%s','%s')\n", __VA_ARGS__);
    3.21  #endif
    3.22  #define DEBUG_LOG(TITLE, ENTITY, DESC) {\
    3.23 -    log_event(session, (TITLE), (ENTITY), (DESC), "debug");\
    3.24 -    LOG_MORE((TITLE), (ENTITY), (DESC))\
    3.25 +    log_event(session, (TITLE), (ENTITY), (DESC), "debug " __FILE__ ":" S_LINE);\
    3.26 +    LOG_MORE((TITLE), (ENTITY), (DESC), __FILE__ ":" S_LINE)\
    3.27  }
    3.28  #endif
    3.29